summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorJuergen Ributzka <juergen@apple.com>2014-04-12 02:36:28 +0000
committerJuergen Ributzka <juergen@apple.com>2014-04-12 02:36:28 +0000
commit6e17aa45a392fa998fe9316267dfd9eb82eeea99 (patch)
tree8b98bf84523a7e6e637365a785b26dd050da1176 /llvm
parenta8c45c9f88c1c6de27c21f217ffdcdabf229cf45 (diff)
downloadbcm5719-llvm-6e17aa45a392fa998fe9316267dfd9eb82eeea99.tar.gz
bcm5719-llvm-6e17aa45a392fa998fe9316267dfd9eb82eeea99.zip
[ARM64] Fix the cost model for cheap large constants.
Originally the cost model would give up for large constants and just return the maximum cost. This is not what we want for constant hoisting, because some of these constants are large in bitwidth, but are still cheap to materialize. This commit fixes the cost model to either return TCC_Free if the cost cannot be determined, or accurately calculate the cost even for large constants (bitwidth > 128). This fixes <rdar://problem/16591573>. llvm-svn: 206100
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/Target/ARM64/ARM64TargetTransformInfo.cpp14
-rw-r--r--llvm/test/Transforms/ConstantHoisting/ARM64/large-immediate.ll8
2 files changed, 17 insertions, 5 deletions
diff --git a/llvm/lib/Target/ARM64/ARM64TargetTransformInfo.cpp b/llvm/lib/Target/ARM64/ARM64TargetTransformInfo.cpp
index f12d1be81a1..cc8cc806ec7 100644
--- a/llvm/lib/Target/ARM64/ARM64TargetTransformInfo.cpp
+++ b/llvm/lib/Target/ARM64/ARM64TargetTransformInfo.cpp
@@ -154,7 +154,7 @@ unsigned ARM64TTI::getIntImmCost(const APInt &Imm, Type *Ty) const {
assert(Ty->isIntegerTy());
unsigned BitSize = Ty->getPrimitiveSizeInBits();
- if (BitSize == 0 || BitSize > 128)
+ if (BitSize == 0)
return ~0U;
// Sign-extend all constants to a multiple of 64-bit.
@@ -179,8 +179,10 @@ unsigned ARM64TTI::getIntImmCost(unsigned Opcode, unsigned Idx,
assert(Ty->isIntegerTy());
unsigned BitSize = Ty->getPrimitiveSizeInBits();
- if (BitSize == 0 || BitSize > 128)
- return ~0U;
+ // There is no cost model for constants with a bit size of 0. Return TCC_Free
+ // here, so that constant hoisting will ignore this constant.
+ if (BitSize == 0)
+ return TCC_Free;
unsigned ImmIdx = ~0U;
switch (Opcode) {
@@ -238,8 +240,10 @@ unsigned ARM64TTI::getIntImmCost(Intrinsic::ID IID, unsigned Idx,
assert(Ty->isIntegerTy());
unsigned BitSize = Ty->getPrimitiveSizeInBits();
- if (BitSize == 0 || BitSize > 128)
- return ~0U;
+ // There is no cost model for constants with a bit size of 0. Return TCC_Free
+ // here, so that constant hoisting will ignore this constant.
+ if (BitSize == 0)
+ return TCC_Free;
switch (IID) {
default:
diff --git a/llvm/test/Transforms/ConstantHoisting/ARM64/large-immediate.ll b/llvm/test/Transforms/ConstantHoisting/ARM64/large-immediate.ll
index 0965a45ea6e..92ad6ee70de 100644
--- a/llvm/test/Transforms/ConstantHoisting/ARM64/large-immediate.ll
+++ b/llvm/test/Transforms/ConstantHoisting/ARM64/large-immediate.ll
@@ -8,3 +8,11 @@ define i128 @test1(i128 %a) nounwind {
ret i128 %2
}
+; Check that we don't hoist large, but cheap constants
+define i512 @test2(i512 %a) nounwind {
+; CHECK-LABEL: test2
+; CHECK-NOT: %const = bitcast i512 7 to i512
+ %1 = and i512 %a, 7
+ %2 = or i512 %1, 7
+ ret i512 %2
+}
OpenPOWER on IntegriCloud