[llvm-bugs] [Bug 24704] New: PowerPC: and (or x, c1), c2) to rlwimi conversion is buggy

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Sep 4 05:02:33 PDT 2015


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

            Bug ID: 24704
           Summary: PowerPC: and (or x, c1), c2) to rlwimi conversion is
                    buggy
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Backend: PowerPC
          Assignee: unassignedbugs at nondot.org
          Reporter: anton at samba.org
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

I'm tracking down a compile issue that looks to be this optimisation:

    // (and (or x, c1), c2) where isRunOfOnes(~(c1^c2)) is a bitfield insert

This is the testcase:

#include <stdio.h>

int m = 1, s, g = 1;
int i;

signed char foo(int p1, int p2)
{
        return p1 - p2;
}

int main(void)
{
        for (i = 0; i < 2; i++) {
                s = 94967289;
                m |= 250;
                printf("%d\n", foo(m & s, g));
        }

        return 0;
}

Building at -O1, I see the output consistent across both iterations as
expected:

-8
-8

Building at -O2, I see it change:

-8
-6

The code produced is:

    10000680:   10 7f 7a 80     lwz     r3,32528(r26)
    10000684:   14 7f 98 80     lwz     r4,32532(r24)
    10000688:   00 00 7c 93     stw     r27,0(r28)
    1000068c:   fa 00 65 60     ori     r5,r3,250
    10000690:   3a 00 23 53     rlwimi  r3,r25,0,0,29
    10000694:   50 18 64 7c     subf    r3,r4,r3
    10000698:   10 7f ba 90     stw     r5,32528(r26)
    1000069c:   74 07 63 7c     extsb   r3,r3
    100006a0:   b4 07 64 7c     extsw   r4,r3
    100006a4:   78 f3 c3 7f     mr      r3,r30
    100006a8:   39 fd ff 4b     bl      100003e0 <00000017.plt_call.printf>
    100006ac:   18 00 41 e8     ld      r2,24(r1)
    100006b0:   00 00 7d 80     lwz     r3,0(r29)
    100006b4:   01 00 63 38     addi    r3,r3,1
    100006b8:   00 00 7d 90     stw     r3,0(r29)
    100006bc:   02 00 03 2c     cmpwi   r3,2
    100006c0:   c0 ff 80 41     blt     10000680

If I remove the rlwimi optimisation, the program gets the correct result. The
only real change is the rlwimi is replaced with an andi.

-- 
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/20150904/292496e3/attachment.html>


More information about the llvm-bugs mailing list