GVNPRE /PRE is not effective

Umesh Kalappa umesh.kalappa0 at gmail.com
Fri Dec 13 03:12:08 PST 2013


Hi All,

The PRE or GVNPRE is not effective for the below use case.

int sum;
int phi =30;
void
f (int i,  int *a)
{
if ((a[i] << (1)) > -15) sum  =(phi+ 0x7fffffffL )/ a[i];
if ((a[i] << (2)) > -15) sum =(phi + 0x7fffffffL) /a[i];

}

respective asm  (clang on trunk )

#clang -O3 -S test.c

 BB#0:                                 # %entry
        pushl   %edi
        pushl   %esi
        movl    12(%esp), %esi
        movl    16(%esp), %edi
        movl    (%edi,%esi,4), %ecx
        leal    (%ecx,%ecx), %eax
        cmpl    $-14, %eax
        jl      .LBB0_2
# BB#1:                                 # %if.then
        movl    $2147483647, %eax       # imm = 0x7FFFFFFF
        addl    phi, %eax
        cltd
        idivl   %ecx
       movl    %eax, sum
        movl    (%edi,%esi,4), %ecx
.LBB0_2:                                # %if.end
        leal    (,%ecx,4), %eax
        cmpl    $-14, %eax
        jl      .LBB0_4
# BB#3:                                 # %if.then5
        movl    $2147483647, %eax       # imm = 0x7FFFFFFF
        addl    phi, %eax
        cltd
        idivl   %ecx
        movl    %eax, sum
.LBB0_4:                                # %if.end9
        popl    %esi
        popl    %edi
        ret


the instruction sequences like
 movl    $2147483647, %eax       # int temp = (phi+ 0x7fffffffL )
  addl    phi, %eax
  cltd

 would had be  hoisted  in the BB0  from BB1 and BB3  or sure i'm
missing something here .


Thanks
~Umesh



More information about the cfe-commits mailing list