[llvm-bugs] [Bug 49640] New: PowerPC: Invalid merging of immediates for D-Form

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Mar 19 04:27:56 PDT 2021


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

            Bug ID: 49640
           Summary: PowerPC: Invalid merging of immediates for D-Form
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: PowerPC
          Assignee: unassignedbugs at nondot.org
          Reporter: nemanja.i.ibm at gmail.com
                CC: llvm-bugs at lists.llvm.org, nemanja.i.ibm at gmail.com

Created attachment 24661
  --> https://bugs.llvm.org/attachment.cgi?id=24661&action=edit
Eigen test reduced by creduce

When a D-Form instruction is fed by an add-immediate, we attempt to merge the
two immediates to form a single displacement so we can remove the
add-immediate.

However, we don't check whether the new displacement fits into a 16-bit signed
immediate field early enough. Namely, we do a sign-extend from 16 bits first
which will discard high bits and then we check whether the result is a 16-bit
signed immediate. It of course will always be.

The check needs to be moved prior to the sign-extend.

Reduced test case from Eigen attached.

To reproduce the problem:
clang -S -O3 -mcpu=pwr9 badDForm.cpp -o - 2>/dev/null | grep stfs
        stfs 0, 25400(7)
        stfs 0, 30480(7)
        stfs 0, -29976(7)
        stfs 0, -24896(7)
        stfs 0, -19816(7)

The correct values (with the peephole turned off):
clang -S -O3 -mcpu=pwr9 badDForm.cpp -o - -mllvm --disable-ppc-peephole
2>/dev/null | grep stfs
        stfs 0, 0(7)
        stfs 0, 5080(7)
        stfs 0, 10160(7)
        stfs 0, 15240(7)
        stfs 0, 20320(7)

-- 
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/20210319/c1725ec7/attachment.html>


More information about the llvm-bugs mailing list