[llvm] [RISCV] Allow constants in tryFoldSelectIntoOp (PR #157376)
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 7 17:59:48 PDT 2025
================
@@ -878,12 +841,12 @@ define i64 @select_add_5(i1 zeroext %cond, i64 %x) {
;
; RV32IMZICOND-LABEL: select_add_5:
; RV32IMZICOND: # %bb.0:
+; RV32IMZICOND-NEXT: czero.nez a1, a1, a0
; RV32IMZICOND-NEXT: addi a3, a1, 128
-; RV32IMZICOND-NEXT: sltu a3, a3, a1
-; RV32IMZICOND-NEXT: czero.nez a4, a1, a0
-; RV32IMZICOND-NEXT: add a2, a2, a3
-; RV32IMZICOND-NEXT: czero.nez a1, a2, a0
-; RV32IMZICOND-NEXT: addi a0, a4, 128
+; RV32IMZICOND-NEXT: sltu a1, a3, a1
+; RV32IMZICOND-NEXT: czero.nez a0, a2, a0
+; RV32IMZICOND-NEXT: add a1, a0, a1
+; RV32IMZICOND-NEXT: mv a0, a3
----------------
preames wrote:
A quick comment on the RV64IMZICOND case just below. This one *isn't* changing because we have a case for lowering constant + nonconstant in zicond which ends lowering as (select c, (nonconstant-constant), 0) + constant. When nonconstant = ADD X, constant, this simplifies away to exactly the form tryFoldSelectIntoOp produces. Note that this only occurs when the type is legal, otherwise you end up with an extend blocking the special case.
(Let's not talk about how long it took me to figure this out, and that the extend was really a red-herring.)
https://github.com/llvm/llvm-project/pull/157376
More information about the llvm-commits
mailing list