[llvm] [SDAG] Make Select-with-Identity-Fold More Flexible; NFC (PR #136554)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 21 03:36:48 PDT 2025
================
@@ -3351,13 +3351,26 @@ class TargetLoweringBase {
}
/// Return true if pulling a binary operation into a select with an identity
- /// constant is profitable. This is the inverse of an IR transform.
+ /// constant is profitable for the given binary operation and type. This is
+ /// the inverse of an IR transform.
/// Example: X + (Cond ? Y : 0) --> Cond ? (X + Y) : X
virtual bool shouldFoldSelectWithIdentityConstant(unsigned BinOpcode,
EVT VT) const {
return false;
}
+ /// Return true if pulling a binary operation into a select with an identity
+ /// constant is profitable for the given binary operation, select operation,
+ /// operand to the binary operation, and select operand that is not the
+ /// identity constant. This is a more fine-grained variant of the previous
+ /// overload that is called only if the previous overload returned true.
+ virtual bool
+ shouldFoldSelectWithIdentityConstant(unsigned BinOpcode,
+ unsigned SelectOpcode, SDValue X,
+ SDValue NonIdConstNode) const {
+ return SelectOpcode == ISD::VSELECT;
+ }
----------------
arsenm wrote:
I think you can avoid that with some shuffling around of the code. We're currently calling shouldFoldSelectWithIdentityConstant eagerly, before the other operand parsing logic to see if we can even do this. Could sink this down into the usage function, and handle the attempted commute internal to foldSelectWithIdentityConstant
https://github.com/llvm/llvm-project/pull/136554
More information about the llvm-commits
mailing list