[llvm-commits] [llvm] r126741 - in /llvm/trunk: lib/Analysis/InstructionSimplify.cpp test/Transforms/InstSimplify/compare.ll
Nick Lewycky
nicholas at mxc.ca
Tue Mar 1 00:15:51 PST 2011
Author: nicholas
Date: Tue Mar 1 02:15:50 2011
New Revision: 126741
URL: http://llvm.org/viewvc/llvm-project?rev=126741&view=rev
Log:
Optimize "icmp pred (urem X, Y), Y" --> true/false depending on pred. There's
more work to do here, "icmp ult (urem X, 10), 11" doesn't optimize away yet.
Fixes example 3 from PR9343!
Modified:
llvm/trunk/lib/Analysis/InstructionSimplify.cpp
llvm/trunk/test/Transforms/InstSimplify/compare.ll
Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=126741&r1=126740&r2=126741&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Tue Mar 1 02:15:50 2011
@@ -1434,6 +1434,9 @@
return ConstantInt::getTrue(CI->getContext());
break;
}
+
+ // TODO: integer div and rem with constant RHS all produce values in a
+ // constant range. We should check whether the comparison is a tautology.
}
// Compare of cast, for example (zext X) != 0 -> X != 0
@@ -1644,6 +1647,21 @@
}
}
+ if (LBO && match(LBO, m_URem(m_Value(), m_Specific(RHS)))) {
+ switch (Pred) {
+ default:
+ break;
+ case ICmpInst::ICMP_EQ:
+ case ICmpInst::ICMP_UGT:
+ case ICmpInst::ICMP_UGE:
+ return ConstantInt::getFalse(RHS->getContext());
+ case ICmpInst::ICMP_NE:
+ case ICmpInst::ICMP_ULT:
+ case ICmpInst::ICMP_ULE:
+ return ConstantInt::getTrue(RHS->getContext());
+ }
+ }
+
// If the comparison is with the result of a select instruction, check whether
// comparing with either branch of the select always yields the same value.
if (isa<SelectInst>(LHS) || isa<SelectInst>(RHS))
Modified: llvm/trunk/test/Transforms/InstSimplify/compare.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/compare.ll?rev=126741&r1=126740&r2=126741&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/compare.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/compare.ll Tue Mar 1 02:15:50 2011
@@ -187,3 +187,19 @@
ret i1 %c
; CHECK: ret i1 %cond
}
+
+define i1 @urem1(i32 %X, i32 %Y) {
+; CHECK: @urem1
+ %A = urem i32 %X, %Y
+ %B = icmp ult i32 %A, %Y
+ ret i1 %B
+; CHECK: ret i1 true
+}
+
+define i1 @urem2(i32 %X, i32 %Y) {
+; CHECK: @urem2
+ %A = urem i32 %X, %Y
+ %B = icmp eq i32 %A, %Y
+ ret i1 %B
+; CHECK ret i1 false
+}
More information about the llvm-commits
mailing list