[llvm] r285075 - [InstCombine] add test and code comment to show potentially misguided icmp trunc transform

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 25 08:16:39 PDT 2016


Author: spatel
Date: Tue Oct 25 10:16:39 2016
New Revision: 285075

URL: http://llvm.org/viewvc/llvm-project?rev=285075&view=rev
Log:
[InstCombine] add test and code comment to show potentially misguided icmp trunc transform

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
    llvm/trunk/test/Transforms/InstCombine/icmp.ll

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=285075&r1=285074&r2=285075&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp Tue Oct 25 10:16:39 2016
@@ -1950,6 +1950,9 @@ Instruction *InstCombiner::foldICmpShlCo
                         And, Constant::getNullValue(And->getType()));
   }
 
+  // FIXME: This transform can create illegal types. Use the DataLayout to
+  // decide when to try this?
+
   // Transform (icmp pred iM (shl iM %v, N), C)
   // -> (icmp pred i(M-N) (trunc %v iM to i(M-N)), (trunc (C>>N))
   // Transform the shl to a trunc if (trunc (C>>N)) has no loss and M-N.

Modified: llvm/trunk/test/Transforms/InstCombine/icmp.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/icmp.ll?rev=285075&r1=285074&r2=285075&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/icmp.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/icmp.ll Tue Oct 25 10:16:39 2016
@@ -1208,6 +1208,19 @@ define i1 @icmp_shl16(i32 %x) {
   ret i1 %cmp
 }
 
+; FIXME: We shouldn't be creating illegal types like i15 in InstCombine.
+
+define i1 @icmp_shl17(i32 %x) {
+; CHECK-LABEL: @icmp_shl17(
+; CHECK-NEXT:    [[TMP1:%.*]] = trunc i32 %x to i15
+; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i15 [[TMP1]], 18
+; CHECK-NEXT:    ret i1 [[CMP]]
+;
+  %shl = shl i32 %x, 17
+  %cmp = icmp slt i32 %shl, 2359296
+  ret i1 %cmp
+}
+
 define <2 x i1> @icmp_shl16_vec(<2 x i32> %x) {
 ; CHECK-LABEL: @icmp_shl16_vec(
 ; CHECK-NEXT:    [[TMP1:%.*]] = trunc <2 x i32> %x to <2 x i16>




More information about the llvm-commits mailing list