[llvm-dev] Dumping branch weights in loop unroll phase

Shubham Narlawar via llvm-dev llvm-dev at lists.llvm.org
Sun Nov 28 09:09:13 PST 2021


On Fri, 26 Nov 2021 at 14:31, Florian Hahn <florian_hahn at apple.com> wrote:

> Hi,
>
> Please avoid double posting.
>

Hello Florian and community,

Sure.


> On Nov 24, 2021, at 16:46, Shubham Narlawar via llvm-dev <
> llvm-dev at lists.llvm.org> wrote:
>
> Hello,
>
> I am using a cross compiler built from llvm trunk source.
>
> Host - x86
> Target - AArch64
>
> I am seeing the same loop unroll dump before and after loop unroll pass
> using flags - "-O2 -funroll-loops". Is there a way to check whether the
> loop has unrolled or not?
>
>
> How are you dumping the IR before/after unrolling? You are comparing the
> IR after all optimizations, note that `-O2 already enables unrolling, so
> adding `-funroll-loops` shouldn’t change much. You can disable unrolling
> though, using `-fno-unroll-loops.`
>


I was dumping using below command for AArch64 target -

clang-14 -O3 -Xclang -disable-llvm-passes -S -emit-llvm store.c -o
store.ll                 //preparing for -O3 but don't run passes

[1]

I am getting same dump for below commands -

opt -S store.ll -loop-unroll -print-before=loop-unroll
opt -S store.ll -loop-unroll -print-after=loop-unroll

[2]

In this case also, I am getting same dump for below commands -

opt -S store.ll -loop-unroll -print-before=loop-unroll -O2
opt -S store.ll -loop-unroll -print-after=loop-unroll -O2

I am suspecting that I am comparing IR after all opts. Is the above method
incorrect to find dump before and after loop unroll? Also, I think at -O2
some other pass is unrolling the loop to some extent?

Reference - https://gcc.godbolt.org/z/shbnG8f4W



>
> To see which loops have been unrolled, you can use optimization remarks,
> e.g. add ` -Rpass=loop-unroll `(https://clang.godbolt.org/z/W418qeaGc)
>  or `-fsave-optimization-record`. https://llvm.org/docs/Remarks.html
>
> As I am seeing both before and after loop unroll dumps as same, is there a
> way to dump branch weights? I tried flag "-stats" but I am not getting any
> warnings or actual branch weights.
>
>
> You can take a look at the metadata in LLVM IR (
> https://llvm.org/docs/BranchWeightMetadata.html) Not sure if there’s a
> pass to dump them in a nice way.
>

>From the above link there does not seem any flag to be passed to clang to
dump branch weights? It's fine even if it is not in a nice way. I am
interested in solving this bug -
https://bugs.llvm.org/show_bug.cgi?id=51185#c2

(Sub-optimal placement of loop exit blocks for AArch64 backend)

Thanks and Regards,
Shubham


>
> Cheers,
> Florian
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20211128/4481b919/attachment.html>


More information about the llvm-dev mailing list