[llvm-bugs] [Bug 31651] New: Wrong code bug after GVN/PRE

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Jan 16 02:08:08 PST 2017


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

            Bug ID: 31651
           Summary: Wrong code bug after GVN/PRE
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: mikael.holmen at ericsson.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

Created attachment 17844
  --> https://llvm.org/bugs/attachment.cgi?id=17844&action=edit
Reproducer

Reproduce with
 opt -S -gvn pre_gvn.ll
Adding 
 -debug-only=gvn
We see e.g
 GVN REMOVING PRE LOAD:   %_tmp79 = load i16, i16* %_tmp78, align 2
and I think it goes wrong during this optimization.

In the input we have something like

    for (int step1 = 0; step1 < LOOP_AMOUNT; step1++)
    {
        lb[step1] = step1 + 7;
        ub[step1] = (step1 == 0 ? 10: ub[step1-1]*10);

        switch(lb[step1]) {
        case 7:    CVAL_VERIFY(step1 == 0);
            CVAL_VERIFY(ub[step1] == 10);
                        __label(511);
            break;
        case 8:    CVAL_VERIFY(step1 == 1);
            CVAL_VERIFY(ub[step1] == 100);
                        __label(512);
            break;
        case 9:    CVAL_VERIFY(step1 == 2);
            CVAL_VERIFY(ub[step1] == 1000);
                        __label(513);
            break;
        default:;
        }

        [...]
    }

    int i, j;
    for ( j = 10, i = 0; j < 101; j=j*10, i++ )
    {
        CVAL_VERIFY(ub[i] == j);
    }

So we have two loops. In the first one the array ub is written (low index
first, high index last), and then in the second loop the content of ub is
checked (low index first, high index last).

After gvn this is changed into something like

    int tmp;
    for (int step1 = 0; step1 < LOOP_AMOUNT; step1++)
    {
        lb[step1] = step1 + 7;
        ub[step1] = (step1 == 0 ? 10: ub[step1-1]*10);

        switch(lb[step1]) {
        case 7:    CVAL_VERIFY(step1 == 0);
                        tmp = ub[step1];
            CVAL_VERIFY(tmp == 10);
                        __label(511);
            break;
        case 8:    CVAL_VERIFY(step1 == 1);
                        tmp = ub[step1];
            CVAL_VERIFY(tmp == 100);
                        __label(512);
            break;
        case 9:    CVAL_VERIFY(step1 == 2);
                        tmp = ub[step1];
            CVAL_VERIFY(tmp == 1000);
                        __label(513);
            break;
        default:;
        }

        [...]
    }

    int i, j;
    for ( j = 10, i = 0; j < 101; j=j*10, i++ )
    {
        CVAL_VERIFY((i == 0 ? tmp : ub[i]) == j);
    }

Note the introduced variable tmp (%_tmp792 in the ll output).

Also note that with this rewrite, after the first loop tmp will contain the
value of the element at the highest index in ub, and then we use tmp in the
first round of the second loop, but there we expect the value of the lowest
index element in ub.

-- 
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/20170116/785c5082/attachment-0001.html>


More information about the llvm-bugs mailing list