aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorChristopher Lamb <christopher.lamb@gmail.com>2007-12-18 21:32:20 +0000
committerChristopher Lamb <christopher.lamb@gmail.com>2007-12-18 21:32:20 +0000
commit7a0678cae6c549a1e11ac0767e04c273c298c0b7 (patch)
treeab9fedb8e4176350b31a3713954215b415645cf1 /lib
parentfeb8893d1757cc4f9400a5969df7f926606e246e (diff)
downloadexternal_llvm-7a0678cae6c549a1e11ac0767e04c273c298c0b7.zip
external_llvm-7a0678cae6c549a1e11ac0767e04c273c298c0b7.tar.gz
external_llvm-7a0678cae6c549a1e11ac0767e04c273c298c0b7.tar.bz2
Fold subtracts into integer compares vs. zero. This improves generate code for this case on X86
from _foo: movl $99, %ecx movl 4(%esp), %eax subl %eax, %ecx xorl %edx, %edx testl %ecx, %ecx cmovs %edx, %eax ret to _foo: xorl %ecx, %ecx movl 4(%esp), %eax cmpl $99, %eax cmovg %ecx, %eax ret git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45173 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 1e4b1c3..166b484 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -4793,7 +4793,24 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
if (isa<UndefValue>(Op1)) // X icmp undef -> undef
return ReplaceInstUsesWith(I, UndefValue::get(Type::Int1Ty));
-
+
+ // (icmp cond (sub m A) 0) ->
+ // (icmp cond m A)
+ {
+ ConstantInt *C1, *C2;
+ Value *A;
+ // Check both arguments of the compare for a matching subtract.
+ if (match(Op0, m_ConstantInt(C1)) && C1->getValue() == 0 &&
+ match(Op1, m_Sub(m_ConstantInt(C2), m_Value(A)))) {
+ // We managed to fold the add into the RHS of the select condition.
+ return new ICmpInst(I.getPredicate(), A, C2);
+ } else if (match(Op1, m_ConstantInt(C1)) && C1->getValue() == 0 &&
+ match(Op0, m_Sub(m_ConstantInt(C2), m_Value(A)))) {
+ // We managed to fold the add into the LHS of the select condition.
+ return new ICmpInst(I.getPredicate(), C2, A);
+ }
+ }
+
// icmp <global/alloca*/null>, <global/alloca*/null> - Global/Stack value
// addresses never equal each other! We already know that Op0 != Op1.
if ((isa<GlobalValue>(Op0) || isa<AllocaInst>(Op0) ||