Issue 107946
Summary [LoongArch] Redundant sext after 32-bit signed divisions
Labels missed-optimization, backend:loongarch, llvm:SelectionDAG
Assignees
Reporter dtcxzyw
    ```
; bin/llc -mtriple=loongarch64 test.ll -o -
define signext i32 @sdiv_si32_ui32_ui32(i32 %a, i32 %b) {
entry:
  %r = sdiv i32 %a, %b
  ret i32 %r
}
```
```
; LA64-LABEL: sdiv_si32_ui32_ui32:
; LA64:       # %bb.0: # %entry
; LA64-NEXT: addi.w $a1, $a1, 0
; LA64-NEXT:    addi.w $a0, $a0, 0
; LA64-NEXT: div.d $a0, $a0, $a1
; LA64-NEXT:    addi.w $a0, $a0, 0
; LA64-NEXT: ret
```
`div.d + addi.w` can be folded into `div.w` since both the divisor and dividend are 32-bit sign-extended.
See https://github.com/llvm/llvm-project/pull/107432/files#r1747088467 for more details.

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

Reply via email to