[PATCH] D85092: [InstSimplify] Peephole optimization for icmp (urem X, Y), X
Xavier Denis via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 2 09:57:44 PDT 2020
xldenis updated this revision to Diff 282457.
xldenis marked an inline comment as done.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D85092/new/
https://reviews.llvm.org/D85092
Files:
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/test/Transforms/InstSimplify/compare.ll
Index: llvm/test/Transforms/InstSimplify/compare.ll
===================================================================
--- llvm/test/Transforms/InstSimplify/compare.ll
+++ llvm/test/Transforms/InstSimplify/compare.ll
@@ -723,6 +723,40 @@
ret i1 %B
}
+define i1 @urem8(i8 %X, i8 %Y) {
+; CHECK-LABEL: @urem8(
+; CHECK-NEXT: ret i1 true
+;
+ %A = urem i8 %X, %Y
+ %B = icmp ule i8 %A, %X
+ ret i1 %B
+}
+
+define i1 @urem9(i8 %X, i8 %Y) {
+ ; CHECK-LABEL: @urem9(
+ ; CHECK-NEXT: ret i1 false
+ ;
+ %A = urem i8 %X, %Y
+ %B = icmp ugt i8 %A, %X
+ ret i1 %B
+}
+
+define i1 @urem10(i8 %X, i8 %Y) {
+ ; CHECK-LABEL: @urem10(
+ ; CHECK-NEXT: ret i1 true
+ %A = urem i8 %X, %Y
+ %B = icmp uge i8 %X, %A
+ ret i1 %B
+}
+
+define i1 @urem11(i8 %X, i8 %Y) {
+ ; CHECK-LABEL: @urem11(
+ ; CHECK-NEXT: ret i1 false
+ %A = urem i8 %X, %Y
+ %B = icmp ult i8 %X, %A
+ ret i1 %B
+}
+
; PR9343 #15
define i1 @srem2(i16 %X, i32 %Y) {
; CHECK-LABEL: @srem2(
Index: llvm/lib/Analysis/InstructionSimplify.cpp
===================================================================
--- llvm/lib/Analysis/InstructionSimplify.cpp
+++ llvm/lib/Analysis/InstructionSimplify.cpp
@@ -2814,6 +2814,14 @@
}
}
+ // icmp pred (urem X, Y), X
+ if (match(LBO, m_URem(m_Specific(RHS), m_Value()))) {
+ if (Pred == ICmpInst::ICMP_ULE)
+ return getTrue(ITy);
+ if (Pred == ICmpInst::ICMP_UGT)
+ return getFalse(ITy);
+ }
+
// x >> y <=u x
// x udiv y <=u x.
if (match(LBO, m_LShr(m_Specific(RHS), m_Value())) ||
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85092.282457.patch
Type: text/x-patch
Size: 1539 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200802/7b395809/attachment.bin>
More information about the llvm-commits
mailing list