[LLVMdev] Eliminate stores with __builtin_assume

Philip Reames
Fri, 03 Jul 2015 20:50:18 -0000

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

On 07/03/2015 03:55 AM, Tom Aernoudt wrote:
>
> 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
>
>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20150703/86c55262/attachment.html>