[llvm] [TTI][RISCV] Unconditionally break critical edges to sink ADDI (PR #108889)

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 16 14:35:46 PDT 2024


================
@@ -61,22 +61,22 @@ define signext i32 @select_const_int_pow2_zero(i1 zeroext %a) nounwind {
 define signext i32 @select_const_int_harder(i1 zeroext %a) nounwind {
 ; RV32-LABEL: select_const_int_harder:
 ; RV32:       # %bb.0:
-; RV32-NEXT:    mv a1, a0
-; RV32-NEXT:    li a0, 6
-; RV32-NEXT:    bnez a1, .LBB3_2
+; RV32-NEXT:    bnez a0, .LBB3_2
 ; RV32-NEXT:  # %bb.1:
 ; RV32-NEXT:    li a0, 38
+; RV32-NEXT:    ret
 ; RV32-NEXT:  .LBB3_2:
+; RV32-NEXT:    li a0, 6
 ; RV32-NEXT:    ret
 ;
 ; RV64-LABEL: select_const_int_harder:
 ; RV64:       # %bb.0:
-; RV64-NEXT:    mv a1, a0
-; RV64-NEXT:    li a0, 6
-; RV64-NEXT:    bnez a1, .LBB3_2
+; RV64-NEXT:    bnez a0, .LBB3_2
 ; RV64-NEXT:  # %bb.1:
 ; RV64-NEXT:    li a0, 38
+; RV64-NEXT:    ret
 ; RV64-NEXT:  .LBB3_2:
+; RV64-NEXT:    li a0, 6
----------------
preames wrote:

These select lowering changes are arguably real regressions.  We are loosing the opportunity to allocate the untaken result into a register and then conditionally overwrite it.  The tail duplication probably wouldn't happen in real code, so we'd end up emitting an extra unconditional jump to bypass the critical edge we split before the join.

Specifically for these selects in tests, most can be done via arithmetic expansions instead.  I started to implement that, but ended up pulling on a few too many intertwined changes.  I do plan to go back to this, but I don't consider the select impact blocking here.  

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


More information about the llvm-commits mailing list