Skip to content

Commit c5b7335

Browse files
committed
[SimplifyCFG] FoldTwoEntryPHINode(): don't fold if either block has it's address taken
Same as with HoistThenElseCodeToIf() (ad87761).
1 parent ad87761 commit c5b7335

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2819,6 +2819,11 @@ static bool FoldTwoEntryPHINode(PHINode *PN, const TargetTransformInfo &TTI,
28192819
}
28202820
assert(DomBlock && "Failed to find root DomBlock");
28212821

2822+
// If either of the blocks has it's address taken, we can't do this fold.
2823+
if ((IfBlock1 && IfBlock1->hasAddressTaken()) ||
2824+
(IfBlock2 && IfBlock2->hasAddressTaken()))
2825+
return Changed;
2826+
28222827
LLVM_DEBUG(dbgs() << "FOUND IF CONDITION! " << *IfCond
28232828
<< " T: " << IfTrue->getName()
28242829
<< " F: " << IfFalse->getName() << "\n");

llvm/test/CodeGen/AArch64/inlineasm-S-constraint.ll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,17 @@ common.ret:
3131
%common.retval = phi i32 [ 0, %loc ], [ 42, %loc2 ]
3232
ret i32 %common.retval
3333
}
34+
35+
define i32 @test_inline_constraint_S_label_tailmerged2(i1 %in) {
36+
; CHECK-LABEL: test_inline_constraint_S_label_tailmerged2:
37+
call void asm sideeffect "adr x0, $0", "S"(i8* blockaddress(@test_inline_constraint_S_label_tailmerged2, %loc))
38+
; CHECK: adr x0, .Ltmp{{[0-9]+}}
39+
br i1 %in, label %loc, label %loc2
40+
common.ret:
41+
%common.retval = phi i32 [ 0, %loc ], [ 42, %loc2 ]
42+
ret i32 %common.retval
43+
loc:
44+
br label %common.ret
45+
loc2:
46+
br label %common.ret
47+
}

llvm/test/Transforms/SimplifyCFG/hoist-from-addresstaken-block.ll

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ define i32 @test_inline_constraint_S_label_tailmerged(i1 %in) {
1010
; CHECK-NEXT: ret i32 [[COMMON_RETVAL]]
1111
;
1212
call void asm sideeffect "adr x0, $0", "S"(i8* blockaddress(@test_inline_constraint_S_label_tailmerged, %loc))
13-
br i1 %in, label %loc, label %loc2
13+
br i1 %in, label %loc, label %loc2
1414
loc:
1515
br label %common.ret
1616
loc2:
@@ -19,3 +19,21 @@ common.ret:
1919
%common.retval = phi i32 [ 0, %loc ], [ 42, %loc2 ]
2020
ret i32 %common.retval
2121
}
22+
23+
define i32 @test_inline_constraint_S_label_tailmerged2(i1 %in) {
24+
; CHECK-LABEL: @test_inline_constraint_S_label_tailmerged2(
25+
; CHECK-NEXT: common.ret:
26+
; CHECK-NEXT: call void asm sideeffect "adr x0, $0", "S"(i8* blockaddress(@test_inline_constraint_S_label_tailmerged, [[COMMON_RET:%.*]]))
27+
; CHECK-NEXT: [[DOT:%.*]] = select i1 [[IN:%.*]], i32 0, i32 42
28+
; CHECK-NEXT: ret i32 [[DOT]]
29+
;
30+
call void asm sideeffect "adr x0, $0", "S"(i8* blockaddress(@test_inline_constraint_S_label_tailmerged, %loc))
31+
br i1 %in, label %loc, label %loc2
32+
common.ret:
33+
%common.retval = phi i32 [ 0, %loc ], [ 42, %loc2 ]
34+
ret i32 %common.retval
35+
loc:
36+
br label %common.ret
37+
loc2:
38+
br label %common.ret
39+
}

0 commit comments

Comments
 (0)