[llvm] 3902f9b - [X86] PromoteMaskArithmetic - explicitly attempt to constant fold zext(c) instead of relying on getNode()
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 9 02:34:39 PST 2024
Author: Simon Pilgrim
Date: 2024-02-09T10:34:25Z
New Revision: 3902f9b6e2d925d50f9a4861d78e5aba07b6ef11
URL: https://github.com/llvm/llvm-project/commit/3902f9b6e2d925d50f9a4861d78e5aba07b6ef11
DIFF: https://github.com/llvm/llvm-project/commit/3902f9b6e2d925d50f9a4861d78e5aba07b6ef11.diff
LOG: [X86] PromoteMaskArithmetic - explicitly attempt to constant fold zext(c) instead of relying on getNode()
Don't rely on isBuildVectorOfConstantSDNodes/getNode to constant fold, this could also help in cases where the constant is behind a bitcast.
Noticed while investigating #80668
Added:
Modified:
llvm/lib/Target/X86/X86ISelLowering.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 7db1b8d4ab74f..5d8a3a9bd5826 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -48026,7 +48026,7 @@ static SDValue PromoteMaskArithmetic(SDValue N, EVT VT, SelectionDAG &DAG,
if (SDValue NN0 = PromoteMaskArithmetic(N0, VT, DAG, Depth + 1))
N0 = NN0;
else {
- // The Left side has to be a trunc.
+ // The left side has to be a trunc.
if (N0.getOpcode() != ISD::TRUNCATE)
return SDValue();
@@ -48040,16 +48040,16 @@ static SDValue PromoteMaskArithmetic(SDValue N, EVT VT, SelectionDAG &DAG,
if (SDValue NN1 = PromoteMaskArithmetic(N1, VT, DAG, Depth + 1))
N1 = NN1;
else {
- // The right side has to be a 'trunc' or a constant vector.
+ // The right side has to be a 'trunc' or a (foldable) constant.
bool RHSTrunc = N1.getOpcode() == ISD::TRUNCATE &&
N1.getOperand(0).getValueType() == VT;
- if (!RHSTrunc && !ISD::isBuildVectorOfConstantSDNodes(N1.getNode()))
- return SDValue();
-
if (RHSTrunc)
N1 = N1.getOperand(0);
+ else if (SDValue Cst =
+ DAG.FoldConstantArithmetic(ISD::ZERO_EXTEND, DL, VT, {N1}))
+ N1 = Cst;
else
- N1 = DAG.getNode(ISD::ZERO_EXTEND, DL, VT, N1);
+ return SDValue();
}
return DAG.getNode(N.getOpcode(), DL, VT, N0, N1);
More information about the llvm-commits
mailing list