[llvm] r219585 - InstCombine: Turn (x != 0 & x <u C) into the canonical range check form (x-1 <u C-1)
Benjamin Kramer
benny.kra at googlemail.com
Sun Oct 12 07:02:35 PDT 2014
Author: d0k
Date: Sun Oct 12 09:02:34 2014
New Revision: 219585
URL: http://llvm.org/viewvc/llvm-project?rev=219585&view=rev
Log:
InstCombine: Turn (x != 0 & x <u C) into the canonical range check form (x-1 <u C-1)
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
llvm/trunk/test/Transforms/InstCombine/and2.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp?rev=219585&r1=219584&r2=219585&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp Sun Oct 12 09:02:34 2014
@@ -930,6 +930,8 @@ Value *InstCombiner::FoldAndOfICmps(ICmp
case ICmpInst::ICMP_ULT:
if (LHSCst == SubOne(RHSCst)) // (X != 13 & X u< 14) -> X < 13
return Builder->CreateICmpULT(Val, LHSCst);
+ if (LHSCst->isNullValue()) // (X != 0 & X u< 14) -> X-1 u< 13
+ return InsertRangeTest(Val, AddOne(LHSCst), RHSCst, false, true);
break; // (X != 13 & X u< 15) -> no change
case ICmpInst::ICMP_SLT:
if (LHSCst == SubOne(RHSCst)) // (X != 13 & X s< 14) -> X < 13
Modified: llvm/trunk/test/Transforms/InstCombine/and2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/and2.ll?rev=219585&r1=219584&r2=219585&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/and2.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/and2.ll Sun Oct 12 09:02:34 2014
@@ -66,3 +66,14 @@ define i1 @test7(i32 %i, i1 %b) {
%and2 = and i1 %and1, %cmp2
ret i1 %and2
}
+
+define i1 @test8(i32 %i) {
+; CHECK-LABEL: @test8(
+; CHECK-NEXT: [[DEC:%.*]] = add i32 %i, -1
+; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[DEC]], 13
+; CHECK-NEXT: ret i1 [[CMP]]
+ %cmp1 = icmp ne i32 %i, 0
+ %cmp2 = icmp ult i32 %i, 14
+ %cond = and i1 %cmp1, %cmp2
+ ret i1 %cond
+}
More information about the llvm-commits
mailing list