[llvm-bugs] [Bug 52568] New: Missing multiple store to single load forwarding

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Nov 20 01:15:09 PST 2021


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

            Bug ID: 52568
           Summary: Missing multiple store to single load forwarding
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: nikita.ppv at gmail.com
                CC: llvm-bugs at lists.llvm.org

The middle end optimizer is currently not able to forward multiple small stores
to a single large load at -O3 (https://llvm.godbolt.org/z/bxE1eKMK9):

define i64 @test(ptr %p) {
  store i32 0, ptr %p
  %p2 = getelementptr i8, ptr %p, i64 4
  store i32 1, ptr %p2
  %v = load i64, ptr %p
  ret i64 %v
}

In my specific use case the large load actually gets decomposed back down to
the two parts using trunc/lshr:

define i32 @test2(ptr %p, ptr %p.out) {
  store i32 0, ptr %p
  %p2 = getelementptr i8, ptr %p, i64 4
  store i32 1, ptr %p2
  %v = load i64, ptr %p
  %v1 = trunc i64 %v to i32
  store i32 %v1, ptr %p.out
  %v2 = lshr i64 %v, 32
  %v3 = trunc i64 %v2 to i32
  ret i32 %v3
}

I'm mentioning this because this case is potentially easier to solve, as one
could effectively forward directly to the trunc.

We do fold these at the DAG level, but by then it is too late to apply cross-BB
followup optimizations.

-- 
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/20211120/70c20eca/attachment-0001.html>


More information about the llvm-bugs mailing list