[PATCH] D25941: Simplify `x >=u x >> y` and `x >=u x udiv y`
Arthur Silva via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 25 09:44:40 PDT 2016
arthurprs updated this revision to Diff 75721.
arthurprs added a comment.
Add more tests covering all 4 cases.
Repository:
rL LLVM
https://reviews.llvm.org/D25941
Files:
lib/Analysis/InstructionSimplify.cpp
test/Transforms/InstSimplify/compare.ll
Index: test/Transforms/InstSimplify/compare.ll
===================================================================
--- test/Transforms/InstSimplify/compare.ll
+++ test/Transforms/InstSimplify/compare.ll
@@ -409,6 +409,22 @@
; CHECK: ret i1 false
}
+define i1 @lshr6(i32 %X, i32 %Y) {
+; CHECK-LABEL: @lshr6(
+ %A = lshr i32 %X, %Y
+ %C = icmp ult i32 %X, %A
+ ret i1 %C
+; CHECK: ret i1 false
+}
+
+define i1 @lshr7(i32 %X, i32 %Y) {
+; CHECK-LABEL: @lshr7(
+ %A = lshr i32 %X, %Y
+ %C = icmp uge i32 %X, %A
+ ret i1 %C
+; CHECK: ret i1 true
+}
+
define i1 @ashr1(i32 %x) {
; CHECK-LABEL: @ashr1(
%s = ashr i32 -1, %x
@@ -583,6 +599,22 @@
; CHECK: ret i1 %C
}
+define i1 @udiv7(i32 %X, i32 %Y) {
+; CHECK-LABEL: @udiv7(
+ %A = udiv i32 %X, %Y
+ %C = icmp ult i32 %X, %A
+ ret i1 %C
+; CHECK: ret i1 false
+}
+
+define i1 @udiv8(i32 %X, i32 %Y) {
+; CHECK-LABEL: @udiv8(
+ %A = udiv i32 %X, %Y
+ %C = icmp uge i32 %X, %A
+ ret i1 %C
+; CHECK: ret i1 true
+}
+
define i1 @mul1(i32 %X) {
; CHECK-LABEL: @mul1(
; Square of a non-zero number is non-zero if there is no overflow.
Index: lib/Analysis/InstructionSimplify.cpp
===================================================================
--- lib/Analysis/InstructionSimplify.cpp
+++ lib/Analysis/InstructionSimplify.cpp
@@ -2857,6 +2857,17 @@
return getTrue(ITy);
}
+ // x >=u x >> y
+ // x >=u x udiv y.
+ if (RBO && (match(RBO, m_LShr(m_Specific(LHS), m_Value())) ||
+ match(RBO, m_UDiv(m_Specific(LHS), m_Value())))) {
+ // icmp pred X, (X op Y)
+ if (Pred == ICmpInst::ICMP_ULT)
+ return getFalse(ITy);
+ if (Pred == ICmpInst::ICMP_UGE)
+ return getTrue(ITy);
+ }
+
// handle:
// CI2 << X == CI
// CI2 << X != CI
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25941.75721.patch
Type: text/x-patch
Size: 1754 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161025/5be7f36e/attachment.bin>
More information about the llvm-commits
mailing list