[llvm] 2702fb1 - [SimplifyCFG] Restart if `removeUndefIntroducingPredecessor()` made changes
Roman Lebedev via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 13 05:45:30 PDT 2021
Author: Roman Lebedev
Date: 2021-08-13T15:45:03+03:00
New Revision: 2702fb11484a6f5d99c712a0e92c221288955c56
URL: https://github.com/llvm/llvm-project/commit/2702fb11484a6f5d99c712a0e92c221288955c56
DIFF: https://github.com/llvm/llvm-project/commit/2702fb11484a6f5d99c712a0e92c221288955c56.diff
LOG: [SimplifyCFG] Restart if `removeUndefIntroducingPredecessor()` made changes
It might changed the condition of a branch into a constant,
so we should restart and constant-fold terminator,
instead of continuing with the tautological "conditional" branch.
This fixes the issue reported at https://reviews.llvm.org/rGf30a7dff8a5b32919951dcbf92e4a9d56c4679ff
Added:
Modified:
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/test/Transforms/SimplifyCFG/tautological-conditional-branch.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 482316c6111f9..c9d4641fd6ddd 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -6634,7 +6634,8 @@ bool SimplifyCFGOpt::simplifyOnceImpl(BasicBlock *BB) {
Changed |= EliminateDuplicatePHINodes(BB);
// Check for and remove branches that will always cause undefined behavior.
- Changed |= removeUndefIntroducingPredecessor(BB, DTU);
+ if (removeUndefIntroducingPredecessor(BB, DTU))
+ return requestResimplify();
// Merge basic blocks into their predecessor if there is only one distinct
// pred, and if there is only one distinct successor of the predecessor, and
diff --git a/llvm/test/Transforms/SimplifyCFG/tautological-conditional-branch.ll b/llvm/test/Transforms/SimplifyCFG/tautological-conditional-branch.ll
index 31ab0fa60dbe8..912598197080e 100644
--- a/llvm/test/Transforms/SimplifyCFG/tautological-conditional-branch.ll
+++ b/llvm/test/Transforms/SimplifyCFG/tautological-conditional-branch.ll
@@ -15,8 +15,7 @@ define void @eggs(i1 %arg, i1 %arg16, %0* %arg17, %0* %arg18, %0* %arg19) {
; CHECK: bb21:
; CHECK-NEXT: [[I:%.*]] = icmp eq %0* [[ARG17:%.*]], null
; CHECK-NEXT: call void @hoge()
-; CHECK-NEXT: [[I26:%.*]] = select i1 [[ARG16:%.*]], %0* null, %0* [[ARG19:%.*]]
-; CHECK-NEXT: [[I27:%.*]] = getelementptr inbounds [[TMP0:%.*]], %0* [[I26]], i64 0, i32 0
+; CHECK-NEXT: [[I27:%.*]] = getelementptr inbounds [[TMP0:%.*]], %0* [[ARG19:%.*]], i64 0, i32 0
; CHECK-NEXT: [[I28:%.*]] = load %1*, %1** [[I27]], align 8
; CHECK-NEXT: call void @pluto.1(%1* [[I28]])
; CHECK-NEXT: call void @pluto()
More information about the llvm-commits
mailing list