[llvm-bugs] [Bug 26154] New: Wrong address space in load pre-splitting in SROA

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Jan 15 00:03:25 PST 2016


https://llvm.org/bugs/show_bug.cgi?id=26154

            Bug ID: 26154
           Summary: Wrong address space in load pre-splitting in SROA
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: escha at apple.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

This is a copy-paste of an internal bug report; I might be able to conjure up a
test case if necessary (it's GPU code with multiple address spaces), but the
bug looks pretty straightforward. The reporter supplied a patch. The context is
a load from addrspace(1) which is then stored to the stack, which SROA
mishandles.

Report:

The problem appears to be that when pre-splitting the load, SROA seems to be
using the address space of the store instead of the address space of the load.
The function is SROA::presplitLoadsAndStores and the code is:

      auto *PartTy = Type::getIntNTy(Ty->getContext(), PartSize * 8);
      auto *PartPtrTy = PartTy->getPointerTo(SI->getPointerAddressSpace());
      …
        PLoad = IRB.CreateAlignedLoad(
            getAdjustedPtr(IRB, DL, LoadBasePtr,
                           APInt(DL.getPointerSizeInBits(), PartOffset),
                           PartPtrTy, LoadBasePtr->getName() + “.”),

diff --git a/lib/Transforms/Scalar/SROA.cpp b/lib/Transforms/Scalar/SROA.cpp
index 9c69b6c..48c907f 100644
--- a/lib/Transforms/Scalar/SROA.cpp
+++ b/lib/Transforms/Scalar/SROA.cpp
@@ -3919,7 +3919,8 @@ bool SROA::presplitLoadsAndStores(AllocaInst &AI,
AllocaSlices &AS) {
         PLoad = IRB.CreateAlignedLoad(
             getAdjustedPtr(IRB, DL, LoadBasePtr,
                            APInt(DL.getPointerSizeInBits(), PartOffset),
-                           PartPtrTy, LoadBasePtr->getName() + "."),
+                           PartTy->getPointerTo(LI->getPointerAddressSpace()),
+                           LoadBasePtr->getName() + "."),
             getAdjustedAlignment(LI, PartOffset, DL), /*IsVolatile*/ false,
             LI->getName());
       }

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160115/4d1cf882/attachment.html>


More information about the llvm-bugs mailing list