[PATCH] Added InstCombine transformation for combining two instructions icmp ult/ule/uge/ugt (ashr/lshr (Const2) %A), (Const1)
David Majnemer
david.majnemer at gmail.com
Fri Nov 28 11:13:57 PST 2014
================
Comment at: lib/Transforms/InstCombine/InstCombineCompares.cpp:1125
@@ +1124,3 @@
+ } else {
+ Result = getConstantIfGreater(true);
+ }
----------------
This should be handled by InstSimplify.
================
Comment at: lib/Transforms/InstCombine/InstCombineCompares.cpp:1136
@@ +1135,3 @@
+ I.getPredicate() == I.ICMP_ULE) {
+ Result = getConstantIfGreater(false);
+ }
----------------
As should this.
================
Comment at: lib/Transforms/InstCombine/InstCombineCompares.cpp:1159
@@ +1158,3 @@
+ if (AP1.ugt(AP2)) {
+ Result = getConstantIfGreater(false);
+ } else if (!IsAShr || !AP2.isNegative()) {
----------------
And this.
================
Comment at: lib/Transforms/InstCombine/InstCombineCompares.cpp:2695-2713
@@ -2593,16 +2694,21 @@
- if (I.isEquality()) {
- ConstantInt *CI2;
- if (match(Op0, m_AShr(m_ConstantInt(CI2), m_Value(A))) ||
- match(Op0, m_LShr(m_ConstantInt(CI2), m_Value(A)))) {
+ ConstantInt *CI2;
+ if (match(Op0, m_AShr(m_ConstantInt(CI2), m_Value(A))) ||
+ match(Op0, m_LShr(m_ConstantInt(CI2), m_Value(A)))) {
+ if (I.isEquality()) {
// (icmp eq/ne (ashr/lshr const2, A), const1)
if (Instruction *Inst = FoldICmpCstShrCst(I, Op0, A, CI, CI2))
return Inst;
+ } else if (I.isUnsigned()) {
+ // (icmp ugt/uge/ult/ule (ashr/lshr const2, A), const1)
+ if (Instruction *Inst = FoldUICmpCstShrCst(I, Op0, A, CI, CI2))
+ return Inst;
}
- if (match(Op0, m_Shl(m_ConstantInt(CI2), m_Value(A)))) {
+ } else if (match(Op0, m_Shl(m_ConstantInt(CI2), m_Value(A)))) {
+ if (I.isEquality()) {
// (icmp eq/ne (shl const2, A), const1)
if (Instruction *Inst = FoldICmpCstShlCst(I, Op0, A, CI, CI2))
return Inst;
}
}
----------------
This code would be more general if you use `m_APInt` instead of `m_ConstantInt`.
================
Comment at: lib/Transforms/InstCombine/InstCombineCompares.cpp:2702
@@ -2600,1 +2701,3 @@
return Inst;
+ } else if (I.isUnsigned()) {
+ // (icmp ugt/uge/ult/ule (ashr/lshr const2, A), const1)
----------------
Can you just make this `if`, I think it makes the control flow a little simpler.
================
Comment at: lib/Transforms/InstCombine/InstCombineCompares.cpp:2707
@@ -2601,2 +2706,3 @@
}
- if (match(Op0, m_Shl(m_ConstantInt(CI2), m_Value(A)))) {
+ } else if (match(Op0, m_Shl(m_ConstantInt(CI2), m_Value(A)))) {
+ if (I.isEquality()) {
----------------
Why is this `else if` now? It should be fine as `if`.
http://reviews.llvm.org/D5518
More information about the llvm-commits
mailing list