diff --git a/lib/Target/ARM64/ARM64TargetTransformInfo.cpp b/lib/Target/ARM64/ARM64TargetTransformInfo.cpp index 8a6253d7681..5323b8965f4 100644 --- a/lib/Target/ARM64/ARM64TargetTransformInfo.cpp +++ b/lib/Target/ARM64/ARM64TargetTransformInfo.cpp @@ -166,7 +166,7 @@ unsigned ARM64TTI::getIntImmCost(const APInt &Imm, Type *Ty) const { // chunk. unsigned Cost = 0; for (unsigned ShiftVal = 0; ShiftVal < BitSize; ShiftVal += 64) { - APInt Tmp = ImmVal.ashr(ShiftVal).getLoBits(64); + APInt Tmp = ImmVal.ashr(ShiftVal).sextOrTrunc(64); int64_t Val = Tmp.getSExtValue(); Cost += getIntImmCost(Val); } diff --git a/test/Transforms/ConstantHoisting/ARM64/large-immediate.ll b/test/Transforms/ConstantHoisting/ARM64/large-immediate.ll new file mode 100644 index 00000000000..0965a45ea6e --- /dev/null +++ b/test/Transforms/ConstantHoisting/ARM64/large-immediate.ll @@ -0,0 +1,10 @@ +; RUN: opt -mtriple=arm64-darwin-unknown -S -consthoist < %s | FileCheck %s + +define i128 @test1(i128 %a) nounwind { +; CHECK-LABEL: test1 +; CHECK: %const = bitcast i128 12297829382473034410122878 to i128 + %1 = add i128 %a, 12297829382473034410122878 + %2 = add i128 %1, 12297829382473034410122878 + ret i128 %2 +} +