[llvm-dev] O2 Aggressive Optimization by Clang
Umesh Kalappa via llvm-dev
llvm-dev at lists.llvm.org
Fri Jul 20 05:21:00 PDT 2018
Edited the Subject.
On Fri, Jul 20, 2018 at 5:50 PM, Umesh Kalappa <umesh.kalappa0 at gmail.com> wrote:
> Hi All ,
>
> We are looking at the C sample i.e
>
> extern int i,j;
>
> int test()
> {
> while(1)
> { i++;
> j=20;
> }
> return 0;
> }
>
> command used :(clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)
> )
> clang -S test.c -O2
>
> the generated asm for x86
>
> .L2:
> jmp .L2
>
> we understand that,the infinite loop is not deterministic ,compiler
> is free to treat as that as UB and do aggressive optimization ,but we
> need keep the side effects like j=20 untouched by optimization .
>
> Please note that using the volatile qualifier for i and j or empty
> asm("") in the while loop,will stop the optimizer ,but we don't want
> do that.
>
> Anyone from the community ,please share their insights why above
> transformation is right ?
>
> and without using volatile or memory barrier ,how we can stop the
> above transformation .
>
>
> Thank you in advance.
> ~Umesh
More information about the llvm-dev
mailing list