If you run clang with no optimization level specified, it outputs IR that
is marked "optnone" and when you run opt it will skip optimizing. You
can
prevent this by passing "-Xclang -disable-O0-optnone".
Or alternatively, you can pass -O1 and pass "-Xclang
-disable-llvm-passes"
which will stop immediately after the frontend generates the IR and it
won't run any of the optimization steps.
~Craig
On Tue, Jun 26, 2018 at 3:45 PM luck.caile via llvm-dev <
llvm-dev at lists.llvm.org> wrote:
> test.cpp:
>
> int main() {
>
> int ret = 0;
>
> for (int i = 0; i < 100; i++) {
>
> ret += i;
>
> }
>
> return ret;
>
> }
>
>
>
> Hi,
>
> I’m new to clang/llvm recently and interested in doing some stuff in
> optimization passes.
>
> I tried to play above simple test with clang and see if I could get
> expected llvm IR by enabling llvm loop unrolling of a count 2.
>
> Here are my attempts:
>
> 1. adding pragma before loop in test.cpp: #pragma clang loop
> unroll_count(2)
>
> It did not unroll the loop.
>
> 1. clang++ -c -emit-llvm -S -std=c++11 test.cpp
>
> opt test.ll -mem2reg -loop-unroll -unroll-count=2 -unroll-allow-partial -S
>
> It did not unroll the loop.
>
> In addition, by enabling -debug, I saw message “Skipping ‘Unroll Loops’
> pass…..”
>
> 1. clang++ -c -emit-llvm -S -std=c++11 -O1 test.cpp
>
> It unrolled the loop completely and directly return the final result(4950).
>
>
>
> I assume that my llvm and clang are latest and installed correctly.
>
> Could someone please let me know what I am missing here?
>
>
>
> Thanks,
>
> Kai
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20180626/dff7045c/attachment.html>