[llvm] [RISCV] Generalize existing SRA combine to fix #101040. (PR #101610)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 1 23:13:59 PDT 2024


dtcxzyw wrote:

Can you add a test without zbb?
https://godbolt.org/z/5oKaq5Tjv
```
define signext i32 @func0000000000000001(i32 signext %0, i8 signext %1) #0 {
entry:
  %2 = shl i8 %1, 3
  %3 = ashr i8 %2, 7
  %4 = sext i8 %3 to i32
  %5 = add nsw i32 %4, %0
  ret i32 %5
}
```
Before:
```
func0000000000000001:                   # @func0000000000000001
        slli    a1, a1, 59
        srai    a1, a1, 56
        srli    a1, a1, 7
        addw    a0, a1, a0
        ret
```

After:
```
func0000000000000001:                   # @func0000000000000001
        slli    a1, a1, 59
        srai    a1, a1, 63
        addw    a0, a1, a0
        ret
```

https://github.com/llvm/llvm-project/pull/101610


More information about the llvm-commits mailing list