[PATCH] D9819: [TTI/CostModel] improve TTI::getGEPCost and use it in CostModel::getInstructionCost

Haicheng Wu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 30 14:22:11 PST 2016


haicheng added a comment.

Hi Jingyue and Hal,

I believe this patch has a mistake in calling isLegalAddressingMode().  Please check the inlined the comments.

Thank you,

Haicheng Wu



================
Comment at: include/llvm/Analysis/TargetTransformInfoImpl.h:424
+    if (static_cast<T *>(this)->isLegalAddressingMode(
+            PointerType::get(*GTI, AS), const_cast<GlobalValue *>(BaseGV),
+            BaseOffset, HasBaseReg, Scale, AS)) {
----------------
I think we should use *GTI here rather than PointerType::get(*GTI, AS).

For example, on AArch64, the GEP in the following IRs can be folded

```
%"class.boost::array.16" = type { [24 x i32] }
%arrayidx.i17 = getelementptr inbounds %"class.boost::array.16", %"class.boost::array.16"* %moves, i64 0, i32 0, i64 %conv7                                                                               
store i32 %add, i32* %arrayidx.i17, align 4, !tbaa !18
```
The assembly is simple as

```
str     w24, [x20, x8, lsl #2]
```

However, isLegalAddressingMode() here returns false because we pass a wrong type.

I checked the implementation of isLegalAddressingMode() in several different backends (including ARM) and several other passes (LoopStrengthReduce and CodeGenPrepare) that call isLegalAddressingMode().  It think I am correct.


https://reviews.llvm.org/D9819





More information about the llvm-commits mailing list