[PATCH] D42262: [JumpThreading] Don't restrict cast-traversal to i1

Chad Rosier via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 9 08:47:11 PST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL327150: [JumpThreading] Don't restrict cast-traversal to i1 (authored by mcrosier, committed by ).

Repository:
  rL LLVM

https://reviews.llvm.org/D42262

Files:
  llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp
  llvm/trunk/test/Transforms/JumpThreading/basic.ll


Index: llvm/trunk/test/Transforms/JumpThreading/basic.ll
===================================================================
--- llvm/trunk/test/Transforms/JumpThreading/basic.ll
+++ llvm/trunk/test/Transforms/JumpThreading/basic.ll
@@ -547,6 +547,34 @@
 ; CHECK: }
 }
 
+define i1 @trunc_switch(i1 %arg) {
+; CHECK-LABEL: @trunc_switch
+top:
+; CHECK: br i1 %arg, label %exitA, label %exitB
+  br i1 %arg, label %common, label %B
+
+B:
+  br label %common
+
+common:
+  %phi = phi i8 [ 2, %B ], [ 1, %top ]
+  %trunc = trunc i8 %phi to i2
+; CHECK-NOT: switch
+  switch i2 %trunc, label %unreach [
+    i2 1, label %exitA
+    i2 -2, label %exitB
+  ]
+
+unreach:
+  unreachable
+
+exitA:
+  ret i1 true
+
+exitB:
+  ret i1 false
+}
+
 ; CHECK-LABEL: define void @h_con(i32 %p) {
 define void @h_con(i32 %p) {
   %x = icmp ult i32 %p, 5
Index: llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp
===================================================================
--- llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp
+++ llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp
@@ -656,11 +656,9 @@
   }
 
   // Handle Cast instructions.  Only see through Cast when the source operand is
-  // PHI or Cmp and the source type is i1 to save the compilation time.
+  // PHI or Cmp to save the compilation time.
   if (CastInst *CI = dyn_cast<CastInst>(I)) {
     Value *Source = CI->getOperand(0);
-    if (!Source->getType()->isIntegerTy(1))
-      return false;
     if (!isa<PHINode>(Source) && !isa<CmpInst>(Source))
       return false;
     ComputeValueKnownInPredecessors(Source, BB, Result, Preference, CxtI);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42262.137766.patch
Type: text/x-patch
Size: 1611 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180309/d17f736c/attachment.bin>


More information about the llvm-commits mailing list