[PATCH] D12210: [InstCombine] Transform A & (L - 1) u< L --> L != 0
Sanjoy Das via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 20 15:32:55 PDT 2015
This revision was automatically updated to reflect the committed changes.
Closed by commit rL245635: [InstCombine] Transform A & (L - 1) u< L --> L != 0 (authored by sanjoy).
Changed prior to commit:
http://reviews.llvm.org/D12210?vs=32751&id=32760#toc
Repository:
rL LLVM
http://reviews.llvm.org/D12210
Files:
llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/trunk/test/Transforms/InstCombine/icmp.ll
Index: llvm/trunk/test/Transforms/InstCombine/icmp.ll
===================================================================
--- llvm/trunk/test/Transforms/InstCombine/icmp.ll
+++ llvm/trunk/test/Transforms/InstCombine/icmp.ll
@@ -1603,3 +1603,23 @@
%s = select i1 %cmp, i32 10000, i32 0
ret i32 %s
}
+
+; CHECK: @f8(
+; CHECK-NEXT: [[RESULT:%[a-z0-9]+]] = icmp ne i32 %lim, 0
+; CHECK-NEXT: ret i1 [[RESULT]]
+define i1 @f8(i32 %val, i32 %lim) {
+ %lim.sub = add i32 %lim, -1
+ %val.and = and i32 %val, %lim.sub
+ %r = icmp ult i32 %val.and, %lim
+ ret i1 %r
+}
+
+; CHECK: @f9(
+; CHECK-NEXT: [[RESULT:%[a-z0-9]+]] = icmp ne i32 %lim, 0
+; CHECK-NEXT: ret i1 [[RESULT]]
+define i1 @f9(i32 %val, i32 %lim) {
+ %lim.sub = sub i32 %lim, 1
+ %val.and = and i32 %val, %lim.sub
+ %r = icmp ult i32 %val.and, %lim
+ ret i1 %r
+}
Index: llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
===================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -3490,6 +3490,19 @@
}
}
}
+
+ if (BO0) {
+ // Transform A & (L - 1) `ult` L --> L != 0
+ Value *L;
+ auto LSubOne = m_Add(m_Value(L), m_AllOnes());
+ auto BitwiseAnd =
+ m_CombineOr(m_And(m_Value(), LSubOne), m_And(LSubOne, m_Value()));
+
+ if (match(BO0, BitwiseAnd) && I.getPredicate() == ICmpInst::ICMP_ULT) {
+ auto *Zero = Constant::getNullValue(BO0->getType());
+ return new ICmpInst(ICmpInst::ICMP_NE, L, Zero);
+ }
+ }
}
{ Value *A, *B;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12210.32760.patch
Type: text/x-patch
Size: 1640 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150820/97be8300/attachment.bin>
More information about the llvm-commits
mailing list