[LLVMbugs] [Bug 20916] New: More optimize opportunity for constant folding

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Sep 12 00:08:18 PDT 2014


http://llvm.org/bugs/show_bug.cgi?id=20916

            Bug ID: 20916
           Summary: More optimize opportunity for constant folding
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: ishiura-compiler at ml.kwansei.ac.jp
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

The two programs (A.c) and (B.c) only differ by one line
(marked by "// <---HERE"), where (B.c) simply folds local variable a to 1.

Resulting codes by "clang -O3 -S" are different;
the code (A.s) for (A.c) is less optimized than (B.s) for (B.c).

(A.c)
int main (void)
{
    static   int a = 1;
    volatile int b = 1;

    int c = (a / (0 + b)) >= 2;  // <---HERE

    if (c != 0);
    else __builtin_abort();
    return 0;
}

(B.c)
int main (void)
{
    static   int a = 1;
    volatile int b = 1;

    int c = (1 / (0 + b)) >= 2;  // <---HERE

    if (c != 0);
    else __builtin_abort();
    return 0;
}

+-----------------------------+-----------------------------+
|(A.s)                        |(B.s)                        |
+-----------------------------+-----------------------------+
|main:              # @main   |main:              # @main   |
|    .cfi_startproc           |.LFB0:                       |
|# BB#0:            # %entry  |    .cfi_startproc           |
|    pushq  %rax              |                             |
|.Ltmp0:                      |# BB#0:            # %entry  |
|    .cfi_def_cfa_offset 16   |                             |
|    movl   $1, 4(%rsp)       |    movl   $1, -4(%rsp)      |
|    movl   4(%rsp), %eax     |    movl   -4(%rsp), %eax    |
|    leal   1(%rax), %ecx     |                             |
|    cmpl   $2, %ecx          |                             |
|    ja     .LBB0_2           |                             |
|# BB#1:           # %entry   |                             |
|    cmpl   $2, %eax          |                             |
|    jge    .LBB0_3           |                             |
|.LBB0_2:          # %if.end  |                             |
|    xorl   %eax, %eax        |    xorl   %eax, %eax        |
|    popq   %rdx              |                             |
|    retq                     |    retq                     |
|.LBB0_3:          # %if.then |.Ltmp0:                      |
|    callq  abort             |                             |
|    .size  main, .Ltmp1-main |    .size  main, .Ltmp0-main |
|    .cfi_endproc             |    .cfi_endproc             |
+-----------------------------+-----------------------------+

FYI, "gcc-4.4.7 -O2 -S" compiles both (A.c) and (B.c) into (B.s).

$ clang -v
clang version 3.6.0 (trunk 217334)
Target: x86_64-unknown-linux-gnu
Thread model: posix

-- 
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/20140912/a05e1ad6/attachment.html>


More information about the llvm-bugs mailing list