Eliminate stores with __builtin_assume

Hi all,

Is it possible to use __builtin_assume (or something similar like __builtin_unreachable) to eliminate stores?

Eg I would expect that I if I write something as follows the optimizer could optimize away the store to the variable a:

void foo(int* a)

{

__builtin_assume(*a == 0);

*a = 0;

}

But the generated code still writes to the variable:

; Function Attrs: nounwind uwtable

define void @_Z3fooPi(i32* nocapture %a) #0 {

%1 = load i32, i32* %a, align 4, !tbaa !8

%2 = icmp eq i32 %1, 0

tail call void @llvm.assume(i1 %2)

store i32 0, i32* %a, align 4, !tbaa !8

ret void

}

00000000000000a0 <_Z3fooPi>:

a0: c7 07 00 00 00 00 movl $0x0,(%rdi)

a6: c3 retq

Why this store not optimized away?

Is there another way to tell the optimizer that the store can be eliminated?

Regards,

Tom

I don't believe that anyone has explored using assumes for modeling memory. Doing so seems reasonable, but would require some careful thought. The place to start looking would be the GVN pass. Specifically, look at the handling for full redundancy cases. Looking at what we do for known functions (i.e. malloc, calloc) might be a reasonable place to start reading.

Philip