Issue 204486
Summary [RISCV] Performance regression from change in getRegisterCostTableIndex
Labels new issue
Assignees
Reporter KavinTheG
    Noticed this regression on the BPI-F3 (rva22u64_v):
http://lnt.llvm.org/db_default/v4/nts/profile/1438/121/117

<img width="2517" height="843" alt="Image" src="" />

It looks like that the code generated is the identical, but the `s0` and `s2` registers are swapped. I have traced this change to this commit https://github.com/llvm/llvm-project/pull/201501.

Here is the diff I have been able to produce locally. 

```diff
diff --git a/pre/fib2.s b/fib2.s
index a727287..57c5b31 100644
--- a/pre/fib2.s
+++ b/fib2.s
@@ -19,8 +19,8 @@ fib:                                    # @fib
 .cfi_offset s1, -24
        .cfi_offset s2, -32
 .cfi_remember_state
-       li      s2, 2
-       bgeu    a0, s2, .LBB0_2
+       li      s0, 2
+       bgeu    a0, s0, .LBB0_2
 # %bb.1:
 li      a0, 1
        ld      ra, 24(sp)                      # 8-byte Folded Reload
@@ -37,14 +37,14 @@ fib:                                    # @fib
 .LBB0_2:                                # %if.else.preheader
 .cfi_restore_state
        li      s1, 0
-       addi    s0, a0, 1
+ addi    s2, a0, 1
 .LBB0_3:                                # %if.else
 # =>This Inner Loop Header: Depth=1
- addi    a0, s0, -3
+       addi    a0, s2, -3
        call    fib
- addi    s0, s0, -1
+       addi    s2, s2, -1
        add     s1, s1, a0
-       bltu    s2, s0, .LBB0_3
+       bltu    s0, s2, .LBB0_3
 # %bb.4:                                # %return.loopexit
        addi    a0, s1, 1
        ld      ra, 24(sp)                      # 8-byte Folded Reload
@@ -103,6 +103,6 @@ main:                                   # @main
 .asciz  "%ld\n"
        .size   .L.str, 5

-       .ident "clang version 23.0.0git ([email protected]:KavinTheG/llvm-project.git 5e7ec28c5e3a70588bbe9368d3816b009cf3670f)"
+       .ident  "clang version 23.0.0git ([email protected]:KavinTheG/llvm-project.git 86c073af08bac41fe0349eee2bc0279e5f88d6d9)"
        .section ".note.GNU-stack","",@progbits
        .addrsig
```

This is the command I use to compile the code, which I am fairly confident is the same used in these benchmarks (except without -flto, which I don't think is relevant here).

```zsh
 $LBD/bin/clang --target=riscv64-unknown-linux-gnu \
    --sysroot="$RISCV_SYSROOT" \
    -march=rva22u64_v \
    -O3 \
    -S fib2.c -o fib2.s
```

I've only taken a cursory glance at the benchmarks below but I believe the regressions stem from the same commit. 

http://lnt.llvm.org/db_default/v4/nts/profile/1422/141/2
http://lnt.llvm.org/db_default/v4/nts/profile/1354/141/2

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to