[PATCH] D122926: [X86][CostModel] Strip bitcasts when looking for store GEP operand

Arthur Eubanks via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 1 11:21:26 PDT 2022


aeubanks created this revision.
Herald added subscribers: pengfei, zzheng, hiraditya.
Herald added a project: All.
aeubanks requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This heuristic was introduced in D35888 <https://reviews.llvm.org/D35888>. Assuming it is correct, this
patch should make cost modeling a bit more robust.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122926

Files:
  llvm/lib/Target/X86/X86TargetTransformInfo.cpp
  llvm/test/Transforms/LoopUnroll/X86/store_cost.ll


Index: llvm/test/Transforms/LoopUnroll/X86/store_cost.ll
===================================================================
--- llvm/test/Transforms/LoopUnroll/X86/store_cost.ll
+++ llvm/test/Transforms/LoopUnroll/X86/store_cost.ll
@@ -46,7 +46,9 @@
   store i32 %val4, i32* %xptr4
   %val5 = add i32 %counter, 10
   %xptr5 = getelementptr [1024 x i32], [1024 x i32]* %x05, i32 0, i32 %counter
-  store i32 %val5, i32* %xptr5
+  %bc = bitcast i32* %xptr5 to i16*
+  %val5trunc = trunc i32 %val5 to i16
+  store i16 %val5trunc, i16* %bc
   br label %loop.inc
 
 loop.inc:
Index: llvm/lib/Target/X86/X86TargetTransformInfo.cpp
===================================================================
--- llvm/lib/Target/X86/X86TargetTransformInfo.cpp
+++ llvm/lib/Target/X86/X86TargetTransformInfo.cpp
@@ -3901,7 +3901,8 @@
     if (auto *SI = dyn_cast_or_null<StoreInst>(I)) {
       // Store instruction with index and scale costs 2 Uops.
       // Check the preceding GEP to identify non-const indices.
-      if (auto *GEP = dyn_cast<GetElementPtrInst>(SI->getPointerOperand())) {
+      if (auto *GEP = dyn_cast<GetElementPtrInst>(
+              SI->getPointerOperand()->stripPointerCasts())) {
         if (!all_of(GEP->indices(), [](Value *V) { return isa<Constant>(V); }))
           return TTI::TCC_Basic * 2;
       }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122926.419815.patch
Type: text/x-patch
Size: 1323 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220401/14fff548/attachment.bin>


More information about the llvm-commits mailing list