<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:SimSun;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"\@SimSun";
        panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal>Hi Jingyue,<span style='font-size:11.0pt'><o:p></o:p></span></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>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.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>%"class.boost::array.16" = type { [24 x i32] }<o:p></o:p></p><p class=MsoNormal>%arrayidx.i17 = getelementptr inbounds %"class.boost::array.16", %"class.boost::array.16"* %moves, i64 0, i32 0, i64 %conv7                                                                               <o:p></o:p></p><p class=MsoNormal>store i32 %add, i32* %arrayidx.i17, align 4, !tbaa !18<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>GEP can be folded into the Store and the assembly is simple as <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>str     w24, [x20, x8, lsl #2]<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>But the cost model says the GEP cannot be folded.  <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>getGEPCost() calls isLegalAddressingMode() in the following way to check the GEP can be folded or not<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>static_cast<T *>(this)->isLegalAddressingMode(                                                <o:p></o:p></p><p class=MsoNormal>            PointerType::get(*GTI, AS), const_cast<GlobalValue *>(BaseGV),<o:p></o:p></p><p class=MsoNormal>            BaseOffset, HasBaseReg, Scale, AS)<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>It seems to me that the first argument should be *<b>GTI, rather than PointerType::get(</b>*GTI, AS).  In my example, *GTI is i32 and <b>PointerType::get(</b>*GTI, AS) is i32*.  The current implementation fails the last check of AArch64TargetLowering::isLegalAddressingMode() which is <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>AM.Scale > 0 && (uint64_t)AM.Scale == NumBytes<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Because AM.Scale = 4 and NumBytes = 8<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>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?<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>A simplified test case can be<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>gep.ll<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>%"class.boost::array.16" = type { [24 x i32] }<o:p></o:p></p><p class=MsoNormal>define void @test_geps(%"class.boost::array.16"* %moves, i64 %conv7) {<o:p></o:p></p><p class=MsoNormal>  %arrayidx.i17 = getelementptr inbounds %"class.boost::array.16", %"class.boost::array.16"* %moves, i64 0, i32 0, i64 %conv7<o:p></o:p></p><p class=MsoNormal>  ret void<o:p></o:p></p><p class=MsoNormal>}<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Just run it with following command and the cost of GEP should be 0.<o:p></o:p></p><p class=MsoNormal>opt -cost-model -analyze -mtriple=aarch64-gnu-linux  gep.ll<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Thank you in advance,<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>Haicheng Wu<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>Employee of Qualcomm Datacenter Technologies, Inc.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>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.<o:p></o:p></span></p></div></body></html>