[LLVMbugs] [Bug 9315] New: pow() isn't folded

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Feb 24 08:47:46 PST 2011


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

           Summary: pow() isn't folded
           Product: new-bugs
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: regehr at cs.utah.edu
                CC: llvmbugs at cs.uiuc.edu


Sorry if this is known or if I'm missing something.

I'd expect this code to be compiled into a nop:

#include <math.h>
#include <limits.h>
#include <assert.h>

void f1 (void)
{
  signed char min = -pow(2,8)/2;
  assert (min==CHAR_MIN);
}

It is compiled away by any recent version of gcc for x86. However, the versions
of clang that I tried (2,7 and today's SVN) turn this into a library call, an
FP divide, and an assertion check:

regehr at home:~/sat_ops/saved_sat_ops$ ~/z/bin/clang -v
clang version 2.9 (trunk 126385)
Target: i386-pc-linux-gnu
Thread model: posix
regehr at home:~/sat_ops/saved_sat_ops$ ~/z/bin/clang -O pow2.c -S -o -
    .file    "pow2.c"
    .section    .rodata.cst8,"aM", at progbits,8
    .align    8
.LCPI0_0:
    .quad    -4611686018427387904    # double -2.000000e+00
    .text
    .globl    f1
    .align    16, 0x90
    .type    f1, at function
f1:                                     # @f1
# BB#0:                                 # %entry
    pushl    %ebp
    movl    %esp, %ebp
    subl    $24, %esp
    movl    $1075838976, 4(%esp)    # imm = 0x40200000
    movl    $0, (%esp)
    calll    exp2
    fstpl    -8(%ebp)
    movsd    -8(%ebp), %xmm0
    divsd    .LCPI0_0, %xmm0
    cvttsd2si    %xmm0, %eax
    cmpb    $-128, %al
    jne    .LBB0_2
# BB#1:                                 # %cond.end
    addl    $24, %esp
    popl    %ebp
    ret
.LBB0_2:                                # %cond.false
    movl    $.L__PRETTY_FUNCTION__.f1, 12(%esp)
    movl    $8, 8(%esp)
    movl    $.L.str1, 4(%esp)
    movl    $.L.str, (%esp)
    calll    __assert_fail
.Ltmp0:
    .size    f1, .Ltmp0-f1

    .globl    f2
    .align    16, 0x90
    .type    f2, at function
f2:                                     # @f2
# BB#0:                                 # %entry
    pushl    %ebp
    movl    %esp, %ebp
    subl    $8, %esp
    movl    $1075838976, 4(%esp)    # imm = 0x40200000
    movl    $0, (%esp)
    calll    exp2
    addl    $8, %esp
    popl    %ebp
    ret
.Ltmp1:
    .size    f2, .Ltmp1-f2

    .type    .L.str, at object          # @.str
    .section    .rodata.str1.1,"aMS", at progbits,1
.L.str:
    .asciz     "min==(-127-1)"
    .size    .L.str, 14

    .type    .L.str1, at object         # @.str1
.L.str1:
    .asciz     "pow2.c"
    .size    .L.str1, 7

    .type    .L__PRETTY_FUNCTION__.f1, at object # @__PRETTY_FUNCTION__.f1
.L__PRETTY_FUNCTION__.f1:
    .asciz     "void f1()"
    .size    .L__PRETTY_FUNCTION__.f1, 10


    .section    .note.GNU-stack,"", at progbits

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list