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

10 views
Skip to first unread message

Shubham Narlawar via llvm-dev

unread,
Nov 25, 2021, 2:07:14 AM11/25/21
to llvm...@lists.llvm.org
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?

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.

Thanks and Regards,
Shubham
_______________________________________________
LLVM Developers mailing list
llvm...@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

Shubham Narlawar via llvm-dev

unread,
Nov 25, 2021, 6:43:19 PM11/25/21
to llvm...@lists.llvm.org

Florian Hahn via llvm-dev

unread,
Nov 26, 2021, 4:02:01 AM11/26/21
to Shubham Narlawar, llvm-dev
Hi,

Please avoid double posting.

On Nov 24, 2021, at 16:46, Shubham Narlawar via llvm-dev <llvm...@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.` 

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.


Cheers,
Florian

Shubham Narlawar via llvm-dev

unread,
Nov 28, 2021, 12:09:39 PM11/28/21
to Florian Hahn, llvm-dev
On Fri, 26 Nov 2021 at 14:31, Florian Hahn <floria...@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...@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?


 

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
Reply all
Reply to author
Forward
0 new messages