[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:46 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));
----------------
RKSimon wrote:

Use `DAG.getAllOnesConstant()`?

https://github.com/llvm/llvm-project/pull/85932


More information about the llvm-commits mailing list