[llvm] [SDAG] Make Select-with-Identity-Fold More Flexible; NFC (PR #136554)
Marius Kamp via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 21 02:59:31 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;
+ }
----------------
mskamp wrote:
I haven't done this because the previous `shouldFoldSelectWithIdentityConstant()` method is called before calling the `foldSelectWithIdentityConstant()` method twice (at least for commutative operations). When merging the functions, we would call `shouldFoldSelectWithIdentityConstant()` four times in the worst case.
But if that is not a problem, I can merge these functions (as this would clearly be a cleaner interface).
https://github.com/llvm/llvm-project/pull/136554
More information about the llvm-commits
mailing list