Hi Jingyue, When I look at the cost model of GEP for the following IR on AArch64, I have a question about getGEPCost() that you implemented in 2015. %"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 GEP can be folded into the Store and the assembly is simple as str w24, [x20, x8, lsl #2] But the cost model says the GEP cannot be folded. getGEPCost() calls isLegalAddressingMode() in the following way to check the GEP can be folded or not static_cast<T *>(this)->isLegalAddressingMode( PointerType::get(*GTI, AS), const_cast<GlobalValue *>(BaseGV), BaseOffset, HasBaseReg, Scale, AS) It seems to me that the first argument should be *GTI, rather than PointerType::get(*GTI, AS). In my example, *GTI is i32 and PointerType::get(*GTI, AS) is i32*. The current implementation fails the last check of AArch64TargetLowering::isLegalAddressingMode() which is AM.Scale > 0 && (uint64_t)AM.Scale == NumBytes Because AM.Scale = 4 and NumBytes = 8 I checked the implementation of isLegalAddressingMode() in several different backends and several other passes (LoopStrengthReduce and CodeGenPrepare) that call isLegalAddressingMode(). It seems my understanding is correct. Would you please take a look at this? A simplified test case can be gep.ll %"class.boost::array.16" = type { [24 x i32] } define void @test_geps(%"class.boost::array.16"* %moves, i64 %conv7) { %arrayidx.i17 = getelementptr inbounds %"class.boost::array.16", %"class.boost::array.16"* %moves, i64 0, i32 0, i64 %conv7 ret void } Just run it with following command and the cost of GEP should be 0. opt -cost-model -analyze -mtriple=aarch64-gnu-linux gep.ll Thank you in advance, Haicheng Wu Employee of Qualcomm Datacenter Technologies, Inc. Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161118/7439fd25/attachment.html>