[llvm] r280928 - [Thumb1] Fix cost calculation for complemented immediates
James Molloy via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 8 05:58:04 PDT 2016
Author: jamesm
Date: Thu Sep 8 07:58:04 2016
New Revision: 280928
URL: http://llvm.org/viewvc/llvm-project?rev=280928&view=rev
Log:
[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... :/
Added:
llvm/trunk/test/CodeGen/ARM/immcost.ll
Modified:
llvm/trunk/lib/Target/ARM/ARMTargetTransformInfo.cpp
Modified: llvm/trunk/lib/Target/ARM/ARMTargetTransformInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMTargetTransformInfo.cpp?rev=280928&r1=280927&r2=280928&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMTargetTransformInfo.cpp (original)
+++ llvm/trunk/lib/Target/ARM/ARMTargetTransformInfo.cpp Thu Sep 8 07:58:04 2016
@@ -41,7 +41,7 @@ int ARMTTIImpl::getIntImmCost(const APIn
// 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;
Added: llvm/trunk/test/CodeGen/ARM/immcost.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/immcost.ll?rev=280928&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/ARM/immcost.ll (added)
+++ llvm/trunk/test/CodeGen/ARM/immcost.ll Thu Sep 8 07:58:04 2016
@@ -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
+}
More information about the llvm-commits
mailing list