[llvm] ad48367 - [JumpThreading] Let SimplifyPartiallyRedundantLoad look into freeze
Juneyoung Lee via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 30 23:28:34 PDT 2020
Author: Juneyoung Lee
Date: 2020-07-31T15:28:24+09:00
New Revision: ad48367722b23dd373e612c1c53b16290ae10194
URL: https://github.com/llvm/llvm-project/commit/ad48367722b23dd373e612c1c53b16290ae10194
DIFF: https://github.com/llvm/llvm-project/commit/ad48367722b23dd373e612c1c53b16290ae10194.diff
LOG: [JumpThreading] Let SimplifyPartiallyRedundantLoad look into freeze
This patch allows SimplifyPartiallyRedundantLoad work when
the branch condition was frozen.
Reviewed By: efriedma
Differential Revision: https://reviews.llvm.org/D84944
Added:
Modified:
llvm/lib/Transforms/Scalar/JumpThreading.cpp
llvm/test/Transforms/JumpThreading/pre-load.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
index 37a588a58299..2a5bbfff1e1e 100644
--- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp
+++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
@@ -1168,6 +1168,11 @@ bool JumpThreadingPass::ProcessBlock(BasicBlock *BB) {
// we see one, check to see if it's partially redundant. If so, insert a PHI
// which can then be used to thread the values.
Value *SimplifyValue = CondInst;
+
+ if (auto *FI = dyn_cast<FreezeInst>(SimplifyValue))
+ // Look into freeze's operand
+ SimplifyValue = FI->getOperand(0);
+
if (CmpInst *CondCmp = dyn_cast<CmpInst>(SimplifyValue))
if (isa<Constant>(CondCmp->getOperand(1)))
SimplifyValue = CondCmp->getOperand(0);
diff --git a/llvm/test/Transforms/JumpThreading/pre-load.ll b/llvm/test/Transforms/JumpThreading/pre-load.ll
index 0a8af988477f..d5df3acf6f7a 100644
--- a/llvm/test/Transforms/JumpThreading/pre-load.ll
+++ b/llvm/test/Transforms/JumpThreading/pre-load.ll
@@ -46,19 +46,19 @@ NO:
define i32 @pre_freeze(i1 %cond, i32 %n) {
; CHECK-LABEL: @pre_freeze(
-; CHECK-NEXT: br i1 [[COND:%.*]], label [[A:%.*]], label [[C:%.*]]
-; CHECK: A:
+; CHECK-NEXT: br i1 [[COND:%.*]], label [[C_THREAD:%.*]], label [[C:%.*]]
+; CHECK: C.thread:
; CHECK-NEXT: store i32 0, i32* @x, align 4
-; CHECK-NEXT: br label [[C]]
+; CHECK-NEXT: br label [[YES:%.*]]
; CHECK: C:
-; CHECK-NEXT: [[PTR:%.*]] = phi i32* [ @x, [[A]] ], [ @y, [[TMP0:%.*]] ]
-; CHECK-NEXT: [[A:%.*]] = load i32, i32* [[PTR]], align 4
-; CHECK-NEXT: [[COND2:%.*]] = icmp eq i32 [[A]], 0
+; CHECK-NEXT: [[A_PR:%.*]] = load i32, i32* @y, align 4
+; CHECK-NEXT: [[COND2:%.*]] = icmp eq i32 [[A_PR]], 0
; CHECK-NEXT: [[COND2_FR:%.*]] = freeze i1 [[COND2]]
-; CHECK-NEXT: br i1 [[COND2_FR]], label [[YES:%.*]], label [[NO:%.*]]
+; CHECK-NEXT: br i1 [[COND2_FR]], label [[YES]], label [[NO:%.*]]
; CHECK: YES:
+; CHECK-NEXT: [[A5:%.*]] = phi i32 [ 0, [[C_THREAD]] ], [ [[A_PR]], [[C]] ]
; CHECK-NEXT: call void @f()
-; CHECK-NEXT: ret i32 [[A]]
+; CHECK-NEXT: ret i32 [[A5]]
; CHECK: NO:
; CHECK-NEXT: call void @g()
; CHECK-NEXT: ret i32 1
More information about the llvm-commits
mailing list