[PATCH] D16809: [JumpThreading] See through Cast Instructions
Haicheng Wu via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 4 13:13:31 PST 2016
haicheng updated this revision to Diff 46952.
haicheng added a comment.
Fix the format of the test case. Thank you, Geoff.
Repository:
rL LLVM
http://reviews.llvm.org/D16809
Files:
lib/Transforms/Scalar/JumpThreading.cpp
test/Transforms/JumpThreading/basic.ll
Index: test/Transforms/JumpThreading/basic.ll
===================================================================
--- test/Transforms/JumpThreading/basic.ll
+++ test/Transforms/JumpThreading/basic.ll
@@ -476,6 +476,43 @@
; CHECK: }
}
+
+;;; Verify that we can handle constraint propagation through cast.
+define i32 @test16(i1 %cond) {
+Entry:
+; CHECK-LABEL: @test16(
+ br i1 %cond, label %Merge, label %F1
+
+; CHECK: Entry:
+; CHECK-NEXT: br i1 %cond, label %F2, label %Merge
+
+F1:
+ %v1 = call i32 @f1()
+ br label %Merge
+
+Merge:
+ %B = phi i32 [1, %Entry], [%v1, %F1]
+ %M = icmp eq i32 %B, 0
+ %M1 = zext i1 %M to i32
+ %N = icmp eq i32 %M1, 1
+ br i1 %N, label %T2, label %F2
+
+; CHECK: Merge:
+; CHECK-NOT: phi
+; CHECK-NEXT: %v1 = call i32 @f1()
+
+T2:
+ %Q = zext i1 %M to i32
+ ret i32 %Q
+
+F2:
+ ret i32 %B
+; CHECK: F2:
+; CHECK-NEXT: phi i32
+}
+
+
+
; In this test we check that block duplication is inhibited by the presence
; of a function with the 'noduplicate' attribute.
Index: lib/Transforms/Scalar/JumpThreading.cpp
===================================================================
--- lib/Transforms/Scalar/JumpThreading.cpp
+++ lib/Transforms/Scalar/JumpThreading.cpp
@@ -465,6 +465,20 @@
return !Result.empty();
}
+ // Handle Cast instructions.
+ if (CastInst *CI = dyn_cast<CastInst>(I)) {
+ ComputeValueKnownInPredecessors(CI->getOperand(0), BB, Result, Preference,
+ CxtI);
+ if (Result.empty())
+ return false;
+
+ // Cast the known values.
+ for (auto &R : Result)
+ R.first = ConstantExpr::getCast(CI->getOpcode(), R.first, CI->getType());
+
+ return true;
+ }
+
PredValueInfoTy LHSVals, RHSVals;
// Handle some boolean conditions.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16809.46952.patch
Type: text/x-patch
Size: 1764 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160204/ea2a54fa/attachment.bin>
More information about the llvm-commits
mailing list