From 21a466ca4dbdb960b428238b72230caf59205a9e Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Sun, 20 Jun 2021 12:33:57 +0300 Subject: [PATCH] [SimplifyCFG] FoldTwoEntryPHINode(): don't fold if either block has it's address taken Same as with HoistThenElseCodeToIf() (ad87761925c2790aab272138b5bbbde4a93e0383). --- lib/Transforms/Utils/SimplifyCFG.cpp | 5 +++++ .../CodeGen/AArch64/inlineasm-S-constraint.ll | 14 +++++++++++++ .../hoist-from-addresstaken-block.ll | 20 ++++++++++++++++++- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp index 4f3559d9779..6c3acb8bbc7 100644 --- a/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/lib/Transforms/Utils/SimplifyCFG.cpp @@ -2819,6 +2819,11 @@ static bool FoldTwoEntryPHINode(PHINode *PN, const TargetTransformInfo &TTI, } assert(DomBlock && "Failed to find root DomBlock"); + // If either of the blocks has it's address taken, we can't do this fold. + if ((IfBlock1 && IfBlock1->hasAddressTaken()) || + (IfBlock2 && IfBlock2->hasAddressTaken())) + return Changed; + LLVM_DEBUG(dbgs() << "FOUND IF CONDITION! " << *IfCond << " T: " << IfTrue->getName() << " F: " << IfFalse->getName() << "\n"); diff --git a/test/CodeGen/AArch64/inlineasm-S-constraint.ll b/test/CodeGen/AArch64/inlineasm-S-constraint.ll index 0e1169500e6..16583bb69c0 100644 --- a/test/CodeGen/AArch64/inlineasm-S-constraint.ll +++ b/test/CodeGen/AArch64/inlineasm-S-constraint.ll @@ -31,3 +31,17 @@ common.ret: %common.retval = phi i32 [ 0, %loc ], [ 42, %loc2 ] ret i32 %common.retval } + +define i32 @test_inline_constraint_S_label_tailmerged2(i1 %in) { +; CHECK-LABEL: test_inline_constraint_S_label_tailmerged2: + call void asm sideeffect "adr x0, $0", "S"(i8* blockaddress(@test_inline_constraint_S_label_tailmerged2, %loc)) +; CHECK: adr x0, .Ltmp{{[0-9]+}} + br i1 %in, label %loc, label %loc2 +common.ret: + %common.retval = phi i32 [ 0, %loc ], [ 42, %loc2 ] + ret i32 %common.retval +loc: + br label %common.ret +loc2: + br label %common.ret +} diff --git a/test/Transforms/SimplifyCFG/hoist-from-addresstaken-block.ll b/test/Transforms/SimplifyCFG/hoist-from-addresstaken-block.ll index d00593e94f9..2fb115504b5 100644 --- a/test/Transforms/SimplifyCFG/hoist-from-addresstaken-block.ll +++ b/test/Transforms/SimplifyCFG/hoist-from-addresstaken-block.ll @@ -10,7 +10,7 @@ define i32 @test_inline_constraint_S_label_tailmerged(i1 %in) { ; CHECK-NEXT: ret i32 [[COMMON_RETVAL]] ; call void asm sideeffect "adr x0, $0", "S"(i8* blockaddress(@test_inline_constraint_S_label_tailmerged, %loc)) -br i1 %in, label %loc, label %loc2 + br i1 %in, label %loc, label %loc2 loc: br label %common.ret loc2: @@ -19,3 +19,21 @@ common.ret: %common.retval = phi i32 [ 0, %loc ], [ 42, %loc2 ] ret i32 %common.retval } + +define i32 @test_inline_constraint_S_label_tailmerged2(i1 %in) { +; CHECK-LABEL: @test_inline_constraint_S_label_tailmerged2( +; CHECK-NEXT: common.ret: +; CHECK-NEXT: call void asm sideeffect "adr x0, $0", "S"(i8* blockaddress(@test_inline_constraint_S_label_tailmerged, [[COMMON_RET:%.*]])) +; CHECK-NEXT: [[DOT:%.*]] = select i1 [[IN:%.*]], i32 0, i32 42 +; CHECK-NEXT: ret i32 [[DOT]] +; + call void asm sideeffect "adr x0, $0", "S"(i8* blockaddress(@test_inline_constraint_S_label_tailmerged, %loc)) + br i1 %in, label %loc, label %loc2 +common.ret: + %common.retval = phi i32 [ 0, %loc ], [ 42, %loc2 ] + ret i32 %common.retval +loc: + br label %common.ret +loc2: + br label %common.ret +}