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: unassignedb...@nondot.org
          Reporter: nemanja.i....@gmail.com
                CC: llvm-bugs@lists.llvm.org, nemanja.i....@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to