[llvm] r281043 - [ARM] icmp %x, -C can be lowered to a simple ADDS or CMN
James Molloy via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 9 06:35:28 PDT 2016
Author: jamesm
Date: Fri Sep 9 08:35:28 2016
New Revision: 281043
URL: http://llvm.org/viewvc/llvm-project?rev=281043&view=rev
Log:
[ARM] icmp %x, -C can be lowered to a simple ADDS or CMN
Tell TargetTransformInfo about this so ConstantHoisting is informed.
Modified:
llvm/trunk/lib/Target/ARM/ARMTargetTransformInfo.cpp
llvm/trunk/test/CodeGen/ARM/immcost.ll
Modified: llvm/trunk/lib/Target/ARM/ARMTargetTransformInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMTargetTransformInfo.cpp?rev=281043&r1=281042&r2=281043&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMTargetTransformInfo.cpp (original)
+++ llvm/trunk/lib/Target/ARM/ARMTargetTransformInfo.cpp Fri Sep 9 08:35:28 2016
@@ -73,6 +73,17 @@ int ARMTTIImpl::getIntImmCost(unsigned O
// Conversion to BIC is free, and means we can use ~Imm instead.
return std::min(getIntImmCost(Imm, Ty), getIntImmCost(~Imm, Ty));
+ if (Opcode == Instruction::ICmp && Imm.isNegative() &&
+ Ty->getIntegerBitWidth() == 32) {
+ int64_t NegImm = -Imm.getSExtValue();
+ if (ST->isThumb2() && NegImm < 1<<12)
+ // icmp X, #-C -> cmn X, #C
+ return 0;
+ if (ST->isThumb() && NegImm < 1<<8)
+ // icmp X, #-C -> adds X, #C
+ return 0;
+ }
+
return getIntImmCost(Imm, Ty);
}
Modified: llvm/trunk/test/CodeGen/ARM/immcost.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/immcost.ll?rev=281043&r1=281042&r2=281043&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/ARM/immcost.ll (original)
+++ llvm/trunk/test/CodeGen/ARM/immcost.ll Fri Sep 9 08:35:28 2016
@@ -37,3 +37,37 @@ ret:
ret void
}
+; CHECK: Function: test_icmp_neg
+; CHECK-NOT: Collect constant
+define void @test_icmp_neg(i1 %cond, i32 %arg, i32 %arg2) {
+entry:
+ %a = icmp ne i32 %arg, -5
+ call void @g2(i1 %a)
+ br i1 %cond, label %true, label %ret
+
+true:
+ %b = icmp ne i32 %arg2, -5
+ call void @g2(i1 %b)
+ br label %ret
+
+ret:
+ ret void
+}
+declare void @g2(i1)
+
+; CHECK: Function: test_icmp_neg2
+; CHECK: Hoist constant (i32 -500) to BB entry
+define void @test_icmp_neg2(i1 %cond, i32 %arg, i32 %arg2) {
+entry:
+ %a = icmp ne i32 %arg, -500
+ call void @g2(i1 %a)
+ br i1 %cond, label %true, label %ret
+
+true:
+ %b = icmp ne i32 %arg2, -500
+ call void @g2(i1 %b)
+ br label %ret
+
+ret:
+ ret void
+}
More information about the llvm-commits
mailing list