[PATCH] D109388: [AArch64][CostModel] Use cost of target trunc type when only use of a non-register sized load

Andrew Litteken via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 7 12:58:56 PDT 2021


AndrewLitteken created this revision.
AndrewLitteken added reviewers: fhahn, paquette, samparker.
Herald added subscribers: hiraditya, kristof.beyls.
AndrewLitteken requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The code size cost model for AArch64 uses the legalization cost for the type of the pointer of a load.  If this load is followed directly by a trunc instruction, and is the only use of the result of the load, only one instruction is generated in the target assembly language.  This adds a check for this case, and uses the target type of the trunc instruction if so.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D109388

Files:
  llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
  llvm/test/Analysis/CostModel/AArch64/load-to-trunc.ll


Index: llvm/test/Analysis/CostModel/AArch64/load-to-trunc.ll
===================================================================
--- /dev/null
+++ 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
Index: llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
===================================================================
--- llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
+++ 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<TruncInst>(*I->user_begin()))
+      Ty = TI->getDestTy();
+  }
   EVT VT = TLI->getValueType(DL, Ty, true);
   // Type legalization can't handle structs
   if (VT == MVT::Other)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109388.371157.patch
Type: text/x-patch
Size: 1873 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210907/a5fe80e3/attachment.bin>


More information about the llvm-commits mailing list