[llvm] [SelectionDAG] Treat CopyFromReg as freezing the value (PR #85932)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 24 03:07:47 PDT 2024
================
@@ -15379,6 +15379,26 @@ SDValue DAGCombiner::visitFREEZE(SDNode *N) {
N0.getOpcode() == ISD::BUILD_PAIR ||
N0.getOpcode() == ISD::CONCAT_VECTORS;
+ // Avoid turning a BUILD_VECTOR that can be recognized as "all zeros", "all
+ // ones" or "constant" into something that depends on FrozenUndef. We can
+ // instead pick undef values to keep those properties, while at the same time
+ // folding away the freeze.
+ // If we implement a more general solution for folding away freeze(undef) in
+ // the future, then this special handling can be removed.
+ if (N0.getOpcode() == ISD::BUILD_VECTOR) {
+ SDLoc DL(N0);
+ MVT VT = N0.getSimpleValueType();
+ MVT EltVT = VT.getVectorElementType();
+ if (llvm::ISD::isBuildVectorAllOnes(N0.getNode()))
+ return DAG.getSplatBuildVector(VT, DL, DAG.getConstant(-1, DL, EltVT));
+ if (llvm::ISD::isBuildVectorOfConstantSDNodes(N0.getNode())) {
+ SmallVector<SDValue, 8> NewVecC;
+ for (const SDValue &Op : N0->op_values())
+ NewVecC.push_back(Op.isUndef() ? DAG.getConstant(0, DL, EltVT) : Op);
----------------
RKSimon wrote:
Using EltVT doesn't account for BUILD_VECTOR implicit truncation - it needs to be:
```cpp
DAG.getConstant(0, DL, Op.getValueType())
```
https://github.com/llvm/llvm-project/pull/85932
More information about the llvm-commits
mailing list