diff --git a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp --- a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp +++ b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp @@ -1459,6 +1459,10 @@ unsigned AddressSpace, TTI::TargetCostKind CostKind, const Instruction *I) { + if(I && I->hasOneUse()) { + if (const TruncInst *TI = dyn_cast(*I->user_begin())) + Ty = TI->getDestTy(); + } EVT VT = TLI->getValueType(DL, Ty, true); // Type legalization can't handle structs if (VT == MVT::Other) diff --git a/llvm/test/Analysis/CostModel/AArch64/load-to-trunc.ll b/llvm/test/Analysis/CostModel/AArch64/load-to-trunc.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Analysis/CostModel/AArch64/load-to-trunc.ll @@ -0,0 +1,21 @@ +; Check memory cost model action for a load of an unusually sized integer +; follow by and a trunc to a register sized integer gives a cost of 1 rather +; than the expanded cost if it is not. + +; RUN: opt -cost-model -analyze -mtriple=aarch64--linux-gnu < %s | FileCheck %s --check-prefix=CHECK + +; Check that cost is 1 for unusual load to +define i32 @loadUnusualIntegerWithTrunc(i1228* %ptr) { +; CHECK: 'Cost Model Analysis' for function 'loadUnusualIntegerWithTrunc': +; CHECK: Cost Model: Found an estimated cost of 1 for instruction: + %out = load i1228, i1228* %ptr + %trunc = trunc i1228 %out to i32 + ret i32 %trunc +} + +define i1228 @loadUnusualInteger(i1228* %ptr) { +; CHECK: 'Cost Model Analysis' for function 'loadUnusualInteger': +; CHECKa load : Cost Model: Found an estimated cost of 32 for instruction: + %out = load i1228, i1228* %ptr + ret i1228 %out +} \ No newline at end of file