[llvm] c5b7335 - [SimplifyCFG] FoldTwoEntryPHINode(): don't fold if either block has it's address taken
Roman Lebedev via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 20 02:37:51 PDT 2021
Author: Roman Lebedev
Date: 2021-06-20T12:37:14+03:00
New Revision: c5b7335dc8ebdf6c007363631ae154e97ea4a733
URL: https://github.com/llvm/llvm-project/commit/c5b7335dc8ebdf6c007363631ae154e97ea4a733
DIFF: https://github.com/llvm/llvm-project/commit/c5b7335dc8ebdf6c007363631ae154e97ea4a733.diff
LOG: [SimplifyCFG] FoldTwoEntryPHINode(): don't fold if either block has it's address taken
Same as with HoistThenElseCodeToIf() (ad87761925c2790aab272138b5bbbde4a93e0383).
Added:
Modified:
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/test/CodeGen/AArch64/inlineasm-S-constraint.ll
llvm/test/Transforms/SimplifyCFG/hoist-from-addresstaken-block.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 4f3559d9779b..6c3acb8bbc7a 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/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/llvm/test/CodeGen/AArch64/inlineasm-S-constraint.ll b/llvm/test/CodeGen/AArch64/inlineasm-S-constraint.ll
index 0e1169500e68..16583bb69c03 100644
--- a/llvm/test/CodeGen/AArch64/inlineasm-S-constraint.ll
+++ b/llvm/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/llvm/test/Transforms/SimplifyCFG/hoist-from-addresstaken-block.ll b/llvm/test/Transforms/SimplifyCFG/hoist-from-addresstaken-block.ll
index d00593e94f9f..2fb115504b51 100644
--- a/llvm/test/Transforms/SimplifyCFG/hoist-from-addresstaken-block.ll
+++ b/llvm/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
+}
More information about the llvm-commits
mailing list