[PATCH] D26524: [AArch64] Sink sext when foldable in user GEPs

Jun Bum Lim via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 11 09:12:56 PST 2016


junbuml added inline comments.


================
Comment at: lib/Target/AArch64/AArch64AddressTypePromotion.cpp:394
+    gep_type_iterator GTI = gep_type_begin(GEPInst);
+    for (unsigned i = 1, e = GEPInst->getNumOperands(); i != e; ++i, ++GTI) {
+      if (GEPInst->getOperand(i) == SExtInst) {
----------------
jmolloy wrote:
> Shouldn't this function only succeed if the SExt was the *last* operand in the GEP? We can't represent a GEP such as:
> 
>   %0 = sext i16 %idx to i32
>   %1 = gep inbounds i32* %base, i32 %0, i32 6
> 
> So I think this function is not conservative enough.
If we are accessing an element from a struct pointer, such GEP could be used where a constant is placed after the sext to index the element in struct. The test case shows such case.  For example, if you see func_16B(), %addr2 is to access the 2nd element in %struct.16B :  

  %addr2 = getelementptr inbounds %struct.16B, %struct.16B* %P, i64 %s_ext, i32 1

Since all other indexes are constants, it will end up with a simple add in the form of %base + TypeSize * sext + constant, where the sext is used to index a struct object from the struct array.


https://reviews.llvm.org/D26524





More information about the llvm-commits mailing list