summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWeiming Zhao <weimingz@codeaurora.org>2016-06-28 22:30:45 +0000
committerWeiming Zhao <weimingz@codeaurora.org>2016-06-28 22:30:45 +0000
commit5410edddb1dcd2a46fa0f212fb4cb0403ba7431d (patch)
treea9f9ae65a39c91d5d94a3496560052dd97ec674e
parentd16490dfd19f8cdb1ca03388ca762707a501558b (diff)
downloadbcm5719-llvm-5410edddb1dcd2a46fa0f212fb4cb0403ba7431d.tar.gz
bcm5719-llvm-5410edddb1dcd2a46fa0f212fb4cb0403ba7431d.zip
[ARM] Fix 28282: cost computation for constant hoisting
Summary: This fixes bug: https://llvm.org/bugs/show_bug.cgi?id=28282 Currently the cost model of constant hoisting checks the bit width of the data type of the constants. However, the actual immediate value is small enough and not need to be hoisted. This patch checks for the actual bit width needed for the constant. Reviewers: t.p.northover, rengolin Subscribers: aemerson, rengolin, llvm-commits Differential Revision: http://reviews.llvm.org/D21668 llvm-svn: 274073
-rw-r--r--llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp2
-rw-r--r--llvm/test/Transforms/ConstantHoisting/ARM/bad-cases.ll17
2 files changed, 18 insertions, 1 deletions
diff --git a/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp b/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp
index aaec3107aec..ddb5d287780 100644
--- a/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp
+++ b/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp
@@ -19,7 +19,7 @@ int ARMTTIImpl::getIntImmCost(const APInt &Imm, Type *Ty) {
assert(Ty->isIntegerTy());
unsigned Bits = Ty->getPrimitiveSizeInBits();
- if (Bits == 0 || Bits > 64)
+ if (Bits == 0 || Imm.getActiveBits() >= 64)
return 4;
int64_t SImmVal = Imm.getSExtValue();
diff --git a/llvm/test/Transforms/ConstantHoisting/ARM/bad-cases.ll b/llvm/test/Transforms/ConstantHoisting/ARM/bad-cases.ll
index 8fa78e3d69b..ffcfb2e56c9 100644
--- a/llvm/test/Transforms/ConstantHoisting/ARM/bad-cases.ll
+++ b/llvm/test/Transforms/ConstantHoisting/ARM/bad-cases.ll
@@ -90,3 +90,20 @@ loop:
end:
ret void
}
+
+;PR 28282: even when data type is larger than 64-bit, the bit width of the
+;constant operand could be smaller than 64-bit. In this case, there is no
+;benefit to hoist the constant.
+define i32 @struct_type_test(i96 %a0, i96 %a1) {
+;CHECK-LABEL: @struct_type_test
+entry:
+;CHECK-NOT: %const = bitcast i96 32 to i96
+;CHECK: lshr0 = lshr i96 %a0, 32
+ %lshr0 = lshr i96 %a0, 32
+ %cast0 = trunc i96 %lshr0 to i32
+;CHECK: lshr1 = lshr i96 %a1, 32
+ %lshr1 = lshr i96 %a1, 32
+ %cast1 = trunc i96 %lshr1 to i32
+ %ret = add i32 %cast0, %cast1
+ ret i32 %ret
+}
OpenPOWER on IntegriCloud