summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorJames Molloy <james.molloy@arm.com>2016-09-08 12:58:04 +0000
committerJames Molloy <james.molloy@arm.com>2016-09-08 12:58:04 +0000
commit7c7255e40b9115802987690516fb10301e22a313 (patch)
tree623d933c0b418a3ea47c78fcaaaa0094926e7a6d /llvm
parentcc7b4b511bb366dd2b404b4ec176638954e90a3d (diff)
downloadbcm5719-llvm-7c7255e40b9115802987690516fb10301e22a313.tar.gz
bcm5719-llvm-7c7255e40b9115802987690516fb10301e22a313.zip
[Thumb1] Fix cost calculation for complemented immediates
Materializing something like "-3" can be done as 2 instructions: MOV r0, #3 MVN r0, r0 This has a cost of 2, not 3. It looks like we were already trying to detect this pattern in TII::getIntImmCost(), but were taking the complement of the zero-extended value instead of the sign-extended value which is unlikely to ever produce a number < 256. There were no tests failing after changing this... :/ llvm-svn: 280928
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp2
-rw-r--r--llvm/test/CodeGen/ARM/immcost.ll21
2 files changed, 22 insertions, 1 deletions
diff --git a/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp b/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp
index 13c5dc61acd..2d44adc9951 100644
--- a/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp
+++ b/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp
@@ -41,7 +41,7 @@ int ARMTTIImpl::getIntImmCost(const APInt &Imm, Type *Ty) {
// Thumb1.
if (SImmVal >= 0 && SImmVal < 256)
return 1;
- if ((~ZImmVal < 256) || ARM_AM::isThumbImmShiftedVal(ZImmVal))
+ if ((~SImmVal < 256) || ARM_AM::isThumbImmShiftedVal(ZImmVal))
return 2;
// Load from constantpool.
return 3;
diff --git a/llvm/test/CodeGen/ARM/immcost.ll b/llvm/test/CodeGen/ARM/immcost.ll
new file mode 100644
index 00000000000..0d50bedfec1
--- /dev/null
+++ b/llvm/test/CodeGen/ARM/immcost.ll
@@ -0,0 +1,21 @@
+; RUN: llc %s -o - -O1 -debug-only=consthoist 2>&1 | FileCheck %s
+; REQUIRES: asserts
+
+target datalayout = "e-m:o-p:32:32-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32"
+target triple = "thumbv6m-apple-ios8.0.0"
+
+declare void @g(i32)
+
+; CHECK: Collect constant i32 -3 from call void @g(i32 -3) with cost 2
+define void @f(i1 %cond) {
+entry:
+ call void @g(i32 -3)
+ br i1 %cond, label %true, label %ret
+
+true:
+ call void @g(i32 -3)
+ br label %ret
+
+ret:
+ ret void
+}
OpenPOWER on IntegriCloud