Skip to content
This repository was archived by the owner on Sep 2, 2018. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 210e77b

Browse files
author
James Molloy
committedSep 8, 2016
[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... :/ git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280928 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent d88990b commit 210e77b

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed
 

‎lib/Target/ARM/ARMTargetTransformInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ int ARMTTIImpl::getIntImmCost(const APInt &Imm, Type *Ty) {
4141
// Thumb1.
4242
if (SImmVal >= 0 && SImmVal < 256)
4343
return 1;
44-
if ((~ZImmVal < 256) || ARM_AM::isThumbImmShiftedVal(ZImmVal))
44+
if ((~SImmVal < 256) || ARM_AM::isThumbImmShiftedVal(ZImmVal))
4545
return 2;
4646
// Load from constantpool.
4747
return 3;

‎test/CodeGen/ARM/immcost.ll

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
; RUN: llc %s -o - -O1 -debug-only=consthoist 2>&1 | FileCheck %s
2+
; REQUIRES: asserts
3+
4+
target datalayout = "e-m:o-p:32:32-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32"
5+
target triple = "thumbv6m-apple-ios8.0.0"
6+
7+
declare void @g(i32)
8+
9+
; CHECK: Collect constant i32 -3 from call void @g(i32 -3) with cost 2
10+
define void @f(i1 %cond) {
11+
entry:
12+
call void @g(i32 -3)
13+
br i1 %cond, label %true, label %ret
14+
15+
true:
16+
call void @g(i32 -3)
17+
br label %ret
18+
19+
ret:
20+
ret void
21+
}

0 commit comments

Comments
 (0)
This repository has been archived.