[PATCH] D17663: [JumpThreading] See through Cast Instructions
Haicheng Wu via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 26 16:14:48 PST 2016
haicheng created this revision.
haicheng added reviewers: mssimpso, gberry, mcrosier, bmakam.
haicheng added a subscriber: llvm-commits.
haicheng set the repository for this revision to rL LLVM.
Herald added a subscriber: mcrosier.
D16809 can use SimplifyInstruction to fold some combination of cmp/cast in ComputeValueKnownInPredecessors(), but ComputeValueKnownInPredecessors() still cannot see through some cast instructions.
For example, following code is essentially the negation of %M, but SimplifyICmpInst returns null since it does not create new values.
%B = phi i32
%M = icmp eq i32 %B, 0
%M1 = zext i1 %M to i32
%N = icmp eq i32 %M1, 0
So, it is still beneficial to let ComputeValueKnownInPredecessors() see through the cast instructions to capture more jump-threading opportunities in general.
Repository:
rL LLVM
http://reviews.llvm.org/D17663
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
@@ -511,9 +511,42 @@
; CHECK-NEXT: phi i32
}
+define i32 @test17(i1 %cond) {
+Entry:
+; CHECK-LABEL: @test17(
+ 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 [0, %Entry], [%v1, %F1]
+ %M = icmp eq i32 %B, 0
+ %M1 = zext i1 %M to i32
+ %N = icmp eq i32 %M1, 0
+ 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
+}
+
;;; Just check that ComputeValueKnownInPredecessors() does not return true with
;;; no values and triggers the assert in ProcessThreadableEdges().
-define i32 @test17() {
+define i32 @test18() {
entry:
%A = add i32 0, 1
%B = icmp eq i32 %A, 0
Index: lib/Transforms/Scalar/JumpThreading.cpp
===================================================================
--- lib/Transforms/Scalar/JumpThreading.cpp
+++ lib/Transforms/Scalar/JumpThreading.cpp
@@ -475,6 +475,20 @@
return !Result.empty();
}
+ // Handle Cast instructions.
+ if (CastInst *CI = dyn_cast<CastInst>(I)) {
+ ComputeValueKnownInPredecessors(CI->getOperand(0), BB, Result, Preference,
+ Changed, CxtI);
+ if (Result.empty())
+ return false;
+
+ // Invert 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: D17663.49259.patch
Type: text/x-patch
Size: 1832 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160227/62460dda/attachment.bin>
More information about the llvm-commits
mailing list