[llvm] [DAG] isKnownNeverZero - add ISD::UDIV/SDIV DemandedElts handling and tests (PR #183227)

Ayokunle Amodu via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 3 19:00:01 PST 2026


https://github.com/ayokunle321 updated https://github.com/llvm/llvm-project/pull/183227

>From a7f2a651a43723c40dbef797f902007429e69a67 Mon Sep 17 00:00:00 2001
From: Ayokunle Amodu <ayokunle321 at gmail.com>
Date: Tue, 24 Feb 2026 11:59:32 -0700
Subject: [PATCH 1/7] add udiv and sdiv test

---
 .../AArch64/AArch64SelectionDAGTest.cpp       | 34 +++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/llvm/unittests/Target/AArch64/AArch64SelectionDAGTest.cpp b/llvm/unittests/Target/AArch64/AArch64SelectionDAGTest.cpp
index b0c48e8c97995..5c865fa1d6d83 100644
--- a/llvm/unittests/Target/AArch64/AArch64SelectionDAGTest.cpp
+++ b/llvm/unittests/Target/AArch64/AArch64SelectionDAGTest.cpp
@@ -1574,4 +1574,38 @@ TEST_F(AArch64SelectionDAGTest, KnownNeverZero_Select) {
   EXPECT_FALSE(DAG->isKnownNeverZero(VSelect444Big, DemandAll));
   EXPECT_TRUE(DAG->isKnownNeverZero(VSelect4444, DemandAll));
 }
+
+TEST_F(AArch64SelectionDAGTest, KnownNeverZero_Div) {
+  SDLoc Loc;
+
+  auto Cst0 = DAG->getConstant(0, Loc, MVT::i32);
+  auto Cst1 = DAG->getConstant(1, Loc, MVT::i32);
+  auto Cst4 = DAG->getConstant(4, Loc, MVT::i32);
+  auto Neg1 = DAG->getNode(ISD::SUB, Loc, MVT::i32, Cst0, Cst1);
+  auto Neg4 = DAG->getNode(ISD::SUB, Loc, MVT::i32, Cst0, Cst4);
+
+  auto UDiv04 = DAG->getNode(ISD::UDIV, Loc, MVT::i32, Cst0, Cst4);
+  auto UDiv41 = DAG->getNode(ISD::UDIV, Loc, MVT::i32, Cst4, Cst1);
+  auto UDivNeg41 = DAG->getNode(ISD::UDIV, Loc, MVT::i32, Neg4, Cst1);
+  auto UDiv4Neg1 = DAG->getNode(ISD::UDIV, Loc, MVT::i32, Cst4, Neg1);
+  auto UDivNeg1Neg4 = DAG->getNode(ISD::UDIV, Loc, MVT::i32, Neg1, Neg4);
+
+  EXPECT_FALSE(DAG->isKnownNeverZero(UDiv04));
+  EXPECT_TRUE(DAG->isKnownNeverZero(UDiv41));
+  EXPECT_TRUE(DAG->isKnownNeverZero(UDivNeg41));
+  EXPECT_FALSE(DAG->isKnownNeverZero(UDiv4Neg1));
+  EXPECT_TRUE(DAG->isKnownNeverZero(UDivNeg1Neg4));
+
+  auto SDiv04 = DAG->getNode(ISD::SDIV, Loc, MVT::i32, Cst0, Cst4);
+  auto SDiv41 = DAG->getNode(ISD::SDIV, Loc, MVT::i32, Cst4, Cst1);
+  auto SDivNeg41 = DAG->getNode(ISD::SDIV, Loc, MVT::i32, Neg4, Cst1);
+  auto SDiv4Neg1 = DAG->getNode(ISD::SDIV, Loc, MVT::i32, Cst4, Neg1);
+  auto SDivNeg1Neg4 = DAG->getNode(ISD::SDIV, Loc, MVT::i32, Neg1, Neg4);
+
+  EXPECT_FALSE(DAG->isKnownNeverZero(SDiv04));
+  EXPECT_TRUE(DAG->isKnownNeverZero(SDiv41));
+  EXPECT_TRUE(DAG->isKnownNeverZero(SDivNeg41));
+  EXPECT_TRUE(DAG->isKnownNeverZero(SDiv4Neg1));
+  EXPECT_FALSE(DAG->isKnownNeverZero(SDivNeg1Neg4));
+}
 } // end namespace llvm

>From 74a86eba6025961c089f7499d3c5373600d1e555 Mon Sep 17 00:00:00 2001
From: Ayokunle Amodu <ayokunle321 at gmail.com>
Date: Tue, 24 Feb 2026 12:00:35 -0700
Subject: [PATCH 2/7] remove blank space

---
 llvm/unittests/Target/AArch64/AArch64SelectionDAGTest.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/llvm/unittests/Target/AArch64/AArch64SelectionDAGTest.cpp b/llvm/unittests/Target/AArch64/AArch64SelectionDAGTest.cpp
index 5c865fa1d6d83..9833ee3fdbc51 100644
--- a/llvm/unittests/Target/AArch64/AArch64SelectionDAGTest.cpp
+++ b/llvm/unittests/Target/AArch64/AArch64SelectionDAGTest.cpp
@@ -1577,7 +1577,6 @@ TEST_F(AArch64SelectionDAGTest, KnownNeverZero_Select) {
 
 TEST_F(AArch64SelectionDAGTest, KnownNeverZero_Div) {
   SDLoc Loc;
-
   auto Cst0 = DAG->getConstant(0, Loc, MVT::i32);
   auto Cst1 = DAG->getConstant(1, Loc, MVT::i32);
   auto Cst4 = DAG->getConstant(4, Loc, MVT::i32);

>From bede9594a2e2739e535c6aa7842e1b30bef9690d Mon Sep 17 00:00:00 2001
From: Ayokunle Amodu <ayokunle321 at gmail.com>
Date: Tue, 24 Feb 2026 19:33:46 -0700
Subject: [PATCH 3/7] add vector tests

---
 .../lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 1058 +++++++++--------
 .../AArch64/AArch64SelectionDAGTest.cpp       |   80 +-
 2 files changed, 635 insertions(+), 503 deletions(-)

diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index b7f78439505fc..0b5fbd06293c4 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -91,8 +91,8 @@ static SDVTList makeVTList(const EVT *VTs, unsigned NumVTs) {
 }
 
 // Default null implementations of the callbacks.
-void SelectionDAG::DAGUpdateListener::NodeDeleted(SDNode*, SDNode*) {}
-void SelectionDAG::DAGUpdateListener::NodeUpdated(SDNode*) {}
+void SelectionDAG::DAGUpdateListener::NodeDeleted(SDNode *, SDNode *) {}
+void SelectionDAG::DAGUpdateListener::NodeUpdated(SDNode *) {}
 void SelectionDAG::DAGUpdateListener::NodeInserted(SDNode *) {}
 
 void SelectionDAG::DAGNodeDeletedListener::anchor() {}
@@ -100,13 +100,14 @@ void SelectionDAG::DAGNodeInsertedListener::anchor() {}
 
 #define DEBUG_TYPE "selectiondag"
 
-static cl::opt<bool> EnableMemCpyDAGOpt("enable-memcpy-dag-opt",
-       cl::Hidden, cl::init(true),
-       cl::desc("Gang up loads and stores generated by inlining of memcpy"));
+static cl::opt<bool> EnableMemCpyDAGOpt(
+    "enable-memcpy-dag-opt", cl::Hidden, cl::init(true),
+    cl::desc("Gang up loads and stores generated by inlining of memcpy"));
 
-static cl::opt<int> MaxLdStGlue("ldstmemcpy-glue-max",
-       cl::desc("Number limit for gluing ld/st of memcpy."),
-       cl::Hidden, cl::init(0));
+static cl::opt<int>
+    MaxLdStGlue("ldstmemcpy-glue-max",
+                cl::desc("Number limit for gluing ld/st of memcpy."),
+                cl::Hidden, cl::init(0));
 
 static cl::opt<unsigned>
     MaxSteps("has-predecessor-max-steps", cl::Hidden, cl::init(8192),
@@ -127,12 +128,11 @@ unsigned SelectionDAG::getHasPredecessorMaxSteps() { return MaxSteps; }
 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
 /// As such, this method can be used to do an exact bit-for-bit comparison of
 /// two floating point values.
-bool ConstantFPSDNode::isExactlyValue(const APFloat& V) const {
+bool ConstantFPSDNode::isExactlyValue(const APFloat &V) const {
   return getValueAPF().bitwiseIsEqual(V);
 }
 
-bool ConstantFPSDNode::isValueValidForType(EVT VT,
-                                           const APFloat& Val) {
+bool ConstantFPSDNode::isValueValidForType(EVT VT, const APFloat &Val) {
   assert(VT.isFloatingPoint() && "Can only convert between FP types");
 
   // convert modifies in place, so make a copy.
@@ -188,7 +188,8 @@ bool ISD::isConstantSplatVectorAllOnes(const SDNode *N, bool BuildVectorOnly) {
     return isConstantSplatVector(N, SplatVal) && SplatVal.isAllOnes();
   }
 
-  if (N->getOpcode() != ISD::BUILD_VECTOR) return false;
+  if (N->getOpcode() != ISD::BUILD_VECTOR)
+    return false;
 
   unsigned i = 0, e = N->getNumOperands();
 
@@ -197,7 +198,8 @@ bool ISD::isConstantSplatVectorAllOnes(const SDNode *N, bool BuildVectorOnly) {
     ++i;
 
   // Do not accept an all-undef vector.
-  if (i == e) return false;
+  if (i == e)
+    return false;
 
   // Do not accept build_vectors that aren't all constants or which have non-~0
   // elements. We have to be a bit careful here, as the type of the constant
@@ -234,7 +236,8 @@ bool ISD::isConstantSplatVectorAllZeros(const SDNode *N, bool BuildVectorOnly) {
     return isConstantSplatVector(N, SplatVal) && SplatVal.isZero();
   }
 
-  if (N->getOpcode() != ISD::BUILD_VECTOR) return false;
+  if (N->getOpcode() != ISD::BUILD_VECTOR)
+    return false;
 
   bool IsAllUndef = true;
   for (const SDValue &Op : N->op_values()) {
@@ -621,20 +624,20 @@ ISD::CondCode ISD::getSetCCSwappedOperands(ISD::CondCode Operation) {
   // operation.
   unsigned OldL = (Operation >> 2) & 1;
   unsigned OldG = (Operation >> 1) & 1;
-  return ISD::CondCode((Operation & ~6) |  // Keep the N, U, E bits
-                       (OldL << 1) |       // New G bit
-                       (OldG << 2));       // New L bit.
+  return ISD::CondCode((Operation & ~6) | // Keep the N, U, E bits
+                       (OldL << 1) |      // New G bit
+                       (OldG << 2));      // New L bit.
 }
 
 static ISD::CondCode getSetCCInverseImpl(ISD::CondCode Op, bool isIntegerLike) {
   unsigned Operation = Op;
   if (isIntegerLike)
-    Operation ^= 7;   // Flip L, G, E bits, but not U.
+    Operation ^= 7; // Flip L, G, E bits, but not U.
   else
-    Operation ^= 15;  // Flip all of the condition bits.
+    Operation ^= 15; // Flip all of the condition bits.
 
   if (Operation > ISD::SETTRUE2)
-    Operation &= ~8;  // Don't let N and U bits get set.
+    Operation &= ~8; // Don't let N and U bits get set.
 
   return ISD::CondCode(Operation);
 }
@@ -653,17 +656,21 @@ ISD::CondCode ISD::GlobalISel::getSetCCInverse(ISD::CondCode Op,
 /// does not depend on the sign of the input (setne and seteq).
 static int isSignedOp(ISD::CondCode Opcode) {
   switch (Opcode) {
-  default: llvm_unreachable("Illegal integer setcc operation!");
+  default:
+    llvm_unreachable("Illegal integer setcc operation!");
   case ISD::SETEQ:
-  case ISD::SETNE: return 0;
+  case ISD::SETNE:
+    return 0;
   case ISD::SETLT:
   case ISD::SETLE:
   case ISD::SETGT:
-  case ISD::SETGE: return 1;
+  case ISD::SETGE:
+    return 1;
   case ISD::SETULT:
   case ISD::SETULE:
   case ISD::SETUGT:
-  case ISD::SETUGE: return 2;
+  case ISD::SETUGE:
+    return 2;
   }
 }
 
@@ -674,15 +681,15 @@ ISD::CondCode ISD::getSetCCOrOperation(ISD::CondCode Op1, ISD::CondCode Op2,
     // Cannot fold a signed integer setcc with an unsigned integer setcc.
     return ISD::SETCC_INVALID;
 
-  unsigned Op = Op1 | Op2;  // Combine all of the condition bits.
+  unsigned Op = Op1 | Op2; // Combine all of the condition bits.
 
   // If the N and U bits get set, then the resultant comparison DOES suddenly
   // care about orderedness, and it is true when ordered.
   if (Op > ISD::SETTRUE2)
-    Op &= ~16;     // Clear the U bit if the N bit is set.
+    Op &= ~16; // Clear the U bit if the N bit is set.
 
   // Canonicalize illegal integer setcc's.
-  if (IsInteger && Op == ISD::SETUNE)  // e.g. SETUGT | SETULT
+  if (IsInteger && Op == ISD::SETUNE) // e.g. SETUGT | SETULT
     Op = ISD::SETNE;
 
   return ISD::CondCode(Op);
@@ -701,12 +708,21 @@ ISD::CondCode ISD::getSetCCAndOperation(ISD::CondCode Op1, ISD::CondCode Op2,
   // Canonicalize illegal integer setcc's.
   if (IsInteger) {
     switch (Result) {
-    default: break;
-    case ISD::SETUO : Result = ISD::SETFALSE; break;  // SETUGT & SETULT
-    case ISD::SETOEQ:                                 // SETEQ  & SETU[LG]E
-    case ISD::SETUEQ: Result = ISD::SETEQ   ; break;  // SETUGE & SETULE
-    case ISD::SETOLT: Result = ISD::SETULT  ; break;  // SETULT & SETNE
-    case ISD::SETOGT: Result = ISD::SETUGT  ; break;  // SETUGT & SETNE
+    default:
+      break;
+    case ISD::SETUO:
+      Result = ISD::SETFALSE;
+      break;          // SETUGT & SETULT
+    case ISD::SETOEQ: // SETEQ  & SETU[LG]E
+    case ISD::SETUEQ:
+      Result = ISD::SETEQ;
+      break; // SETUGE & SETULE
+    case ISD::SETOLT:
+      Result = ISD::SETULT;
+      break; // SETULT & SETNE
+    case ISD::SETOGT:
+      Result = ISD::SETUGT;
+      break; // SETUGT & SETNE
     }
   }
 
@@ -718,7 +734,7 @@ ISD::CondCode ISD::getSetCCAndOperation(ISD::CondCode Op1, ISD::CondCode Op2,
 //===----------------------------------------------------------------------===//
 
 /// AddNodeIDOpcode - Add the node opcode to the NodeID data.
-static void AddNodeIDOpcode(FoldingSetNodeID &ID, unsigned OpC)  {
+static void AddNodeIDOpcode(FoldingSetNodeID &ID, unsigned OpC) {
   ID.AddInteger(OpC);
 }
 
@@ -729,8 +745,7 @@ static void AddNodeIDValueTypes(FoldingSetNodeID &ID, SDVTList VTList) {
 }
 
 /// AddNodeIDOperands - Various routines for adding operands to the NodeID data.
-static void AddNodeIDOperands(FoldingSetNodeID &ID,
-                              ArrayRef<SDValue> Ops) {
+static void AddNodeIDOperands(FoldingSetNodeID &ID, ArrayRef<SDValue> Ops) {
   for (const auto &Op : Ops) {
     ID.AddPointer(Op.getNode());
     ID.AddInteger(Op.getResNo());
@@ -738,16 +753,15 @@ static void AddNodeIDOperands(FoldingSetNodeID &ID,
 }
 
 /// AddNodeIDOperands - Various routines for adding operands to the NodeID data.
-static void AddNodeIDOperands(FoldingSetNodeID &ID,
-                              ArrayRef<SDUse> Ops) {
+static void AddNodeIDOperands(FoldingSetNodeID &ID, ArrayRef<SDUse> Ops) {
   for (const auto &Op : Ops) {
     ID.AddPointer(Op.getNode());
     ID.AddInteger(Op.getResNo());
   }
 }
 
-static void AddNodeIDNode(FoldingSetNodeID &ID, unsigned OpC,
-                          SDVTList VTList, ArrayRef<SDValue> OpList) {
+static void AddNodeIDNode(FoldingSetNodeID &ID, unsigned OpC, SDVTList VTList,
+                          ArrayRef<SDValue> OpList) {
   AddNodeIDOpcode(ID, OpC);
   AddNodeIDValueTypes(ID, VTList);
   AddNodeIDOperands(ID, OpList);
@@ -760,7 +774,8 @@ static void AddNodeIDCustom(FoldingSetNodeID &ID, const SDNode *N) {
   case ISD::ExternalSymbol:
   case ISD::MCSymbol:
     llvm_unreachable("Should only be used on nodes with operands");
-  default: break;  // Normal nodes don't need extra info.
+  default:
+    break; // Normal nodes don't need extra info.
   case ISD::TargetConstant:
   case ISD::Constant: {
     const ConstantSDNode *C = cast<ConstantSDNode>(N);
@@ -1020,10 +1035,11 @@ static bool doNotCSE(SDNode *N) {
     return true; // Never CSE anything that produces a glue result.
 
   switch (N->getOpcode()) {
-  default: break;
+  default:
+    break;
   case ISD::HANDLENODE:
   case ISD::EH_LABEL:
-    return true;   // Never CSE these nodes.
+    return true; // Never CSE these nodes.
   }
 
   // Check that remaining values produced are not flags.
@@ -1041,7 +1057,7 @@ void SelectionDAG::RemoveDeadNodes() {
   // to the root node, preventing it from being deleted.
   HandleSDNode Dummy(getRoot());
 
-  SmallVector<SDNode*, 128> DeadNodes;
+  SmallVector<SDNode *, 128> DeadNodes;
 
   // Add all obviously-dead nodes to the DeadNodes worklist.
   for (SDNode &Node : allnodes())
@@ -1076,7 +1092,7 @@ void SelectionDAG::RemoveDeadNodes(SmallVectorImpl<SDNode *> &DeadNodes) {
 
     // Next, brutally remove the operand list.  This is safe to do, as there are
     // no cycles in the graph.
-    for (SDNode::op_iterator I = N->op_begin(), E = N->op_end(); I != E; ) {
+    for (SDNode::op_iterator I = N->op_begin(), E = N->op_end(); I != E;) {
       SDUse &Use = *I++;
       SDNode *Operand = Use.getNode();
       Use.set(SDValue());
@@ -1090,8 +1106,8 @@ void SelectionDAG::RemoveDeadNodes(SmallVectorImpl<SDNode *> &DeadNodes) {
   }
 }
 
-void SelectionDAG::RemoveDeadNode(SDNode *N){
-  SmallVector<SDNode*, 16> DeadNodes(1, N);
+void SelectionDAG::RemoveDeadNode(SDNode *N) {
+  SmallVector<SDNode *, 16> DeadNodes(1, N);
 
   // Create a dummy node that adds a reference to the root node, preventing
   // it from being deleted.  (This matters if the root is an operand of the
@@ -1136,7 +1152,7 @@ void SDDbgInfo::erase(const SDNode *Node) {
   DbgValMapType::iterator I = DbgValMap.find(Node);
   if (I == DbgValMap.end())
     return;
-  for (auto &Val: I->second)
+  for (auto &Val : I->second)
     Val->setIsInvalidated();
   DbgValMap.erase(I);
 }
@@ -1238,7 +1254,8 @@ void SelectionDAG::InsertNode(SDNode *N) {
 bool SelectionDAG::RemoveNodeFromCSEMaps(SDNode *N) {
   bool Erased = false;
   switch (N->getOpcode()) {
-  case ISD::HANDLENODE: return false;  // noop.
+  case ISD::HANDLENODE:
+    return false; // noop.
   case ISD::CONDCODE:
     assert(CondCodeNodes[cast<CondCodeSDNode>(N)->get()] &&
            "Cond code doesn't exist!");
@@ -1280,7 +1297,7 @@ bool SelectionDAG::RemoveNodeFromCSEMaps(SDNode *N) {
   // Verify that the node was actually in one of the CSE maps, unless it has a
   // glue result (which cannot be CSE'd) or is one of the special cases that are
   // not subject to CSE.
-  if (!Erased && N->getValueType(N->getNumValues()-1) != MVT::Glue &&
+  if (!Erased && N->getValueType(N->getNumValues() - 1) != MVT::Glue &&
       !N->isMachineOpcode() && !doNotCSE(N)) {
     N->dump(this);
     dbgs() << "\n";
@@ -1294,8 +1311,7 @@ bool SelectionDAG::RemoveNodeFromCSEMaps(SDNode *N) {
 /// maps and modified in place. Add it back to the CSE maps, unless an identical
 /// node already exists, in which case transfer all its users to the existing
 /// node. This transfer can potentially trigger recursive merging.
-void
-SelectionDAG::AddModifiedNodeToCSEMaps(SDNode *N) {
+void SelectionDAG::AddModifiedNodeToCSEMaps(SDNode *N) {
   // For node types that aren't CSE'd, just act as if no identical node
   // already exists.
   if (!doNotCSE(N)) {
@@ -1331,7 +1347,7 @@ SDNode *SelectionDAG::FindModifiedNodeSlot(SDNode *N, SDValue Op,
   if (doNotCSE(N))
     return nullptr;
 
-  SDValue Ops[] = { Op };
+  SDValue Ops[] = {Op};
   FoldingSetNodeID ID;
   AddNodeIDNode(ID, N->getOpcode(), N->getVTList(), Ops);
   AddNodeIDCustom(ID, N);
@@ -1345,13 +1361,12 @@ SDNode *SelectionDAG::FindModifiedNodeSlot(SDNode *N, SDValue Op,
 /// were replaced with those specified.  If this node is never memoized,
 /// return null, otherwise return a pointer to the slot it would take.  If a
 /// node already exists with these operands, the slot will be non-null.
-SDNode *SelectionDAG::FindModifiedNodeSlot(SDNode *N,
-                                           SDValue Op1, SDValue Op2,
+SDNode *SelectionDAG::FindModifiedNodeSlot(SDNode *N, SDValue Op1, SDValue Op2,
                                            void *&InsertPos) {
   if (doNotCSE(N))
     return nullptr;
 
-  SDValue Ops[] = { Op1, Op2 };
+  SDValue Ops[] = {Op1, Op2};
   FoldingSetNodeID ID;
   AddNodeIDNode(ID, N->getOpcode(), N->getVTList(), Ops);
   AddNodeIDCustom(ID, N);
@@ -1443,7 +1458,8 @@ SDNode *SelectionDAG::FindNodeOrInsertPos(const FoldingSetNodeID &ID,
   SDNode *N = CSEMap.FindNodeOrInsertPos(ID, InsertPos);
   if (N) {
     switch (N->getOpcode()) {
-    default: break;
+    default:
+      break;
     case ISD::Constant:
     case ISD::ConstantFP:
       llvm_unreachable("Querying for Constant and ConstantFP nodes requires "
@@ -1520,21 +1536,18 @@ SelectionDAG::getStrictFPExtendOrRound(SDValue Op, SDValue Chain,
 }
 
 SDValue SelectionDAG::getAnyExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT) {
-  return VT.bitsGT(Op.getValueType()) ?
-    getNode(ISD::ANY_EXTEND, DL, VT, Op) :
-    getNode(ISD::TRUNCATE, DL, VT, Op);
+  return VT.bitsGT(Op.getValueType()) ? getNode(ISD::ANY_EXTEND, DL, VT, Op)
+                                      : getNode(ISD::TRUNCATE, DL, VT, Op);
 }
 
 SDValue SelectionDAG::getSExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT) {
-  return VT.bitsGT(Op.getValueType()) ?
-    getNode(ISD::SIGN_EXTEND, DL, VT, Op) :
-    getNode(ISD::TRUNCATE, DL, VT, Op);
+  return VT.bitsGT(Op.getValueType()) ? getNode(ISD::SIGN_EXTEND, DL, VT, Op)
+                                      : getNode(ISD::TRUNCATE, DL, VT, Op);
 }
 
 SDValue SelectionDAG::getZExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT) {
-  return VT.bitsGT(Op.getValueType()) ?
-    getNode(ISD::ZERO_EXTEND, DL, VT, Op) :
-    getNode(ISD::TRUNCATE, DL, VT, Op);
+  return VT.bitsGT(Op.getValueType()) ? getNode(ISD::ZERO_EXTEND, DL, VT, Op)
+                                      : getNode(ISD::TRUNCATE, DL, VT, Op);
 }
 
 SDValue SelectionDAG::getBitcastedAnyExtOrTrunc(SDValue Op, const SDLoc &DL,
@@ -1553,7 +1566,7 @@ SDValue SelectionDAG::getBitcastedAnyExtOrTrunc(SDValue Op, const SDLoc &DL,
 }
 
 SDValue SelectionDAG::getBitcastedSExtOrTrunc(SDValue Op, const SDLoc &DL,
-                                               EVT VT) {
+                                              EVT VT) {
   assert(!VT.isVector());
   auto Type = Op.getValueType();
   SDValue DestOp;
@@ -1568,7 +1581,7 @@ SDValue SelectionDAG::getBitcastedSExtOrTrunc(SDValue Op, const SDLoc &DL,
 }
 
 SDValue SelectionDAG::getBitcastedZExtOrTrunc(SDValue Op, const SDLoc &DL,
-                                               EVT VT) {
+                                              EVT VT) {
   assert(!VT.isVector());
   auto Type = Op.getValueType();
   SDValue DestOp;
@@ -1746,8 +1759,7 @@ SDValue SelectionDAG::getConstant(const ConstantInt &Val, const SDLoc &DL,
     unsigned ViaEltSizeInBits = ViaEltVT.getSizeInBits();
 
     // For scalable vectors, try to use a SPLAT_VECTOR_PARTS node.
-    if (VT.isScalableVector() ||
-        TLI->isOperationLegal(ISD::SPLAT_VECTOR, VT)) {
+    if (VT.isScalableVector() || TLI->isOperationLegal(ISD::SPLAT_VECTOR, VT)) {
       assert(EltVT.getSizeInBits() % ViaEltSizeInBits == 0 &&
              "Can only handle an even split!");
       unsigned Parts = EltVT.getSizeInBits() / ViaEltSizeInBits;
@@ -1950,7 +1962,7 @@ SDValue SelectionDAG::getGlobalAddress(const GlobalValue *GV, const SDLoc &DL,
   auto *N = newSDNode<GlobalAddressSDNode>(
       Opc, DL.getIROrder(), DL.getDebugLoc(), GV, VTs, Offset, TargetFlags);
   CSEMap.InsertNode(N, IP);
-    InsertNode(N);
+  InsertNode(N);
   return SDValue(N, 0);
 }
 
@@ -2083,14 +2095,15 @@ SDValue SelectionDAG::getBasicBlock(MachineBasicBlock *MBB) {
 }
 
 SDValue SelectionDAG::getValueType(EVT VT) {
-  if (VT.isSimple() && (unsigned)VT.getSimpleVT().SimpleTy >=
-      ValueTypeNodes.size())
-    ValueTypeNodes.resize(VT.getSimpleVT().SimpleTy+1);
+  if (VT.isSimple() &&
+      (unsigned)VT.getSimpleVT().SimpleTy >= ValueTypeNodes.size())
+    ValueTypeNodes.resize(VT.getSimpleVT().SimpleTy + 1);
 
-  SDNode *&N = VT.isExtended() ?
-    ExtendedValueTypeNodes[VT] : ValueTypeNodes[VT.getSimpleVT().SimpleTy];
+  SDNode *&N = VT.isExtended() ? ExtendedValueTypeNodes[VT]
+                               : ValueTypeNodes[VT.getSimpleVT().SimpleTy];
 
-  if (N) return SDValue(N, 0);
+  if (N)
+    return SDValue(N, 0);
   N = newSDNode<VTSDNode>(VT);
   InsertNode(N);
   return SDValue(N, 0);
@@ -2098,7 +2111,8 @@ SDValue SelectionDAG::getValueType(EVT VT) {
 
 SDValue SelectionDAG::getExternalSymbol(const char *Sym, EVT VT) {
   SDNode *&N = ExternalSymbols[Sym];
-  if (N) return SDValue(N, 0);
+  if (N)
+    return SDValue(N, 0);
   N = newSDNode<ExternalSymbolSDNode>(false, Sym, 0, getVTList(VT));
   InsertNode(N);
   return SDValue(N, 0);
@@ -2122,7 +2136,8 @@ SDValue SelectionDAG::getTargetExternalSymbol(const char *Sym, EVT VT,
                                               unsigned TargetFlags) {
   SDNode *&N =
       TargetExternalSymbols[std::pair<std::string, unsigned>(Sym, TargetFlags)];
-  if (N) return SDValue(N, 0);
+  if (N)
+    return SDValue(N, 0);
   N = newSDNode<ExternalSymbolSDNode>(true, Sym, TargetFlags, getVTList(VT));
   InsertNode(N);
   return SDValue(N, 0);
@@ -2136,7 +2151,7 @@ SDValue SelectionDAG::getTargetExternalSymbol(RTLIB::LibcallImpl Libcall,
 
 SDValue SelectionDAG::getCondCode(ISD::CondCode Cond) {
   if ((unsigned)Cond >= CondCodeNodes.size())
-    CondCodeNodes.resize(Cond+1);
+    CondCodeNodes.resize(Cond + 1);
 
   if (!CondCodeNodes[Cond]) {
     auto *N = newSDNode<CondCodeSDNode>(Cond);
@@ -2235,9 +2250,9 @@ SDValue SelectionDAG::getVectorShuffle(EVT VT, const SDLoc &dl, SDValue N1,
   // Validate that all indices in Mask are within the range of the elements
   // input to the shuffle.
   int NElts = Mask.size();
-  assert(llvm::all_of(Mask,
-                      [&](int M) { return M < (NElts * 2) && M >= -1; }) &&
-         "Index out of range");
+  assert(
+      llvm::all_of(Mask, [&](int M) { return M < (NElts * 2) && M >= -1; }) &&
+      "Index out of range");
 
   // Copy the mask so we can do any needed cleanup.
   SmallVector<int, 8> MaskVec(Mask);
@@ -2246,7 +2261,8 @@ SDValue SelectionDAG::getVectorShuffle(EVT VT, const SDLoc &dl, SDValue N1,
   if (N1 == N2) {
     N2 = getUNDEF(VT);
     for (int i = 0; i != NElts; ++i)
-      if (MaskVec[i] >= NElts) MaskVec[i] -= NElts;
+      if (MaskVec[i] >= NElts)
+        MaskVec[i] -= NElts;
   }
 
   // Canonicalize shuffle undef, v -> v, undef.  Commute the shuffle mask.
@@ -2314,8 +2330,10 @@ SDValue SelectionDAG::getVectorShuffle(EVT VT, const SDLoc &dl, SDValue N1,
   // If Identity shuffle return that node.
   bool Identity = true, AllSame = true;
   for (int i = 0; i != NElts; ++i) {
-    if (MaskVec[i] >= 0 && MaskVec[i] != i) Identity = false;
-    if (MaskVec[i] != MaskVec[0]) AllSame = false;
+    if (MaskVec[i] >= 0 && MaskVec[i] != i)
+      Identity = false;
+    if (MaskVec[i] != MaskVec[0])
+      AllSame = false;
   }
   if (Identity && NElts)
     return N1;
@@ -2366,12 +2384,12 @@ SDValue SelectionDAG::getVectorShuffle(EVT VT, const SDLoc &dl, SDValue N1,
 
   SDVTList VTs = getVTList(VT);
   FoldingSetNodeID ID;
-  SDValue Ops[2] = { N1, N2 };
+  SDValue Ops[2] = {N1, N2};
   AddNodeIDNode(ID, ISD::VECTOR_SHUFFLE, VTs, Ops);
   for (int i = 0; i != NElts; ++i)
     ID.AddInteger(MaskVec[i]);
 
-  void* IP = nullptr;
+  void *IP = nullptr;
   if (SDNode *E = FindNodeOrInsertPos(ID, dl, IP))
     return SDValue(E, 0);
 
@@ -2440,7 +2458,7 @@ SDValue SelectionDAG::getEHLabel(const SDLoc &dl, SDValue Root,
 SDValue SelectionDAG::getLabelNode(unsigned Opcode, const SDLoc &dl,
                                    SDValue Root, MCSymbol *Label) {
   FoldingSetNodeID ID;
-  SDValue Ops[] = { Root };
+  SDValue Ops[] = {Root};
   AddNodeIDNode(ID, Opcode, getVTList(MVT::Other), Ops);
   ID.AddPointer(Label);
   void *IP = nullptr;
@@ -2552,7 +2570,8 @@ SDValue SelectionDAG::getFreeze(SDValue V, const APInt &DemandedElts,
 SDValue SelectionDAG::getShiftAmountOperand(EVT LHSTy, SDValue Op) {
   EVT OpTy = Op.getValueType();
   EVT ShTy = TLI->getShiftAmountTy(LHSTy, getDataLayout());
-  if (OpTy == ShTy || OpTy.isVector()) return Op;
+  if (OpTy == ShTy || OpTy.isVector())
+    return Op;
 
   return getZExtOrTrunc(Op, SDLoc(Op), ShTy);
 }
@@ -2582,7 +2601,7 @@ SDValue SelectionDAG::expandVAArg(SDNode *Node) {
   // Increment the pointer, VAList, to the next vaarg
   Tmp1 = getNode(ISD::ADD, dl, VAList.getValueType(), VAList,
                  getConstant(getDataLayout().getTypeAllocSize(
-                                               VT.getTypeForEVT(*getContext())),
+                                 VT.getTypeForEVT(*getContext())),
                              dl, VAList.getValueType()));
   // Store the incremented VAList to the legalized pointer
   Tmp1 =
@@ -2692,11 +2711,14 @@ SDValue SelectionDAG::FoldSetCC(EVT VT, SDValue N1, SDValue N2,
 
   // These setcc operations always fold.
   switch (Cond) {
-  default: break;
+  default:
+    break;
   case ISD::SETFALSE:
-  case ISD::SETFALSE2: return getBoolConstant(false, dl, VT, OpVT);
+  case ISD::SETFALSE2:
+    return getBoolConstant(false, dl, VT, OpVT);
   case ISD::SETTRUE:
-  case ISD::SETTRUE2: return getBoolConstant(true, dl, VT, OpVT);
+  case ISD::SETTRUE2:
+    return getBoolConstant(true, dl, VT, OpVT);
 
   case ISD::SETOEQ:
   case ISD::SETOGT:
@@ -2748,58 +2770,69 @@ SDValue SelectionDAG::FoldSetCC(EVT VT, SDValue N1, SDValue N2,
   if (N1CFP && N2CFP) {
     APFloat::cmpResult R = N1CFP->getValueAPF().compare(N2CFP->getValueAPF());
     switch (Cond) {
-    default: break;
-    case ISD::SETEQ:  if (R==APFloat::cmpUnordered)
-                        return GetUndefBooleanConstant();
-                      [[fallthrough]];
-    case ISD::SETOEQ: return getBoolConstant(R==APFloat::cmpEqual, dl, VT,
-                                             OpVT);
-    case ISD::SETNE:  if (R==APFloat::cmpUnordered)
-                        return GetUndefBooleanConstant();
-                      [[fallthrough]];
-    case ISD::SETONE: return getBoolConstant(R==APFloat::cmpGreaterThan ||
-                                             R==APFloat::cmpLessThan, dl, VT,
-                                             OpVT);
-    case ISD::SETLT:  if (R==APFloat::cmpUnordered)
-                        return GetUndefBooleanConstant();
-                      [[fallthrough]];
-    case ISD::SETOLT: return getBoolConstant(R==APFloat::cmpLessThan, dl, VT,
-                                             OpVT);
-    case ISD::SETGT:  if (R==APFloat::cmpUnordered)
-                        return GetUndefBooleanConstant();
-                      [[fallthrough]];
-    case ISD::SETOGT: return getBoolConstant(R==APFloat::cmpGreaterThan, dl,
-                                             VT, OpVT);
-    case ISD::SETLE:  if (R==APFloat::cmpUnordered)
-                        return GetUndefBooleanConstant();
-                      [[fallthrough]];
-    case ISD::SETOLE: return getBoolConstant(R==APFloat::cmpLessThan ||
-                                             R==APFloat::cmpEqual, dl, VT,
-                                             OpVT);
-    case ISD::SETGE:  if (R==APFloat::cmpUnordered)
-                        return GetUndefBooleanConstant();
-                      [[fallthrough]];
-    case ISD::SETOGE: return getBoolConstant(R==APFloat::cmpGreaterThan ||
-                                         R==APFloat::cmpEqual, dl, VT, OpVT);
-    case ISD::SETO:   return getBoolConstant(R!=APFloat::cmpUnordered, dl, VT,
-                                             OpVT);
-    case ISD::SETUO:  return getBoolConstant(R==APFloat::cmpUnordered, dl, VT,
-                                             OpVT);
-    case ISD::SETUEQ: return getBoolConstant(R==APFloat::cmpUnordered ||
-                                             R==APFloat::cmpEqual, dl, VT,
-                                             OpVT);
-    case ISD::SETUNE: return getBoolConstant(R!=APFloat::cmpEqual, dl, VT,
-                                             OpVT);
-    case ISD::SETULT: return getBoolConstant(R==APFloat::cmpUnordered ||
-                                             R==APFloat::cmpLessThan, dl, VT,
-                                             OpVT);
-    case ISD::SETUGT: return getBoolConstant(R==APFloat::cmpGreaterThan ||
-                                             R==APFloat::cmpUnordered, dl, VT,
-                                             OpVT);
-    case ISD::SETULE: return getBoolConstant(R!=APFloat::cmpGreaterThan, dl,
-                                             VT, OpVT);
-    case ISD::SETUGE: return getBoolConstant(R!=APFloat::cmpLessThan, dl, VT,
-                                             OpVT);
+    default:
+      break;
+    case ISD::SETEQ:
+      if (R == APFloat::cmpUnordered)
+        return GetUndefBooleanConstant();
+      [[fallthrough]];
+    case ISD::SETOEQ:
+      return getBoolConstant(R == APFloat::cmpEqual, dl, VT, OpVT);
+    case ISD::SETNE:
+      if (R == APFloat::cmpUnordered)
+        return GetUndefBooleanConstant();
+      [[fallthrough]];
+    case ISD::SETONE:
+      return getBoolConstant(R == APFloat::cmpGreaterThan ||
+                                 R == APFloat::cmpLessThan,
+                             dl, VT, OpVT);
+    case ISD::SETLT:
+      if (R == APFloat::cmpUnordered)
+        return GetUndefBooleanConstant();
+      [[fallthrough]];
+    case ISD::SETOLT:
+      return getBoolConstant(R == APFloat::cmpLessThan, dl, VT, OpVT);
+    case ISD::SETGT:
+      if (R == APFloat::cmpUnordered)
+        return GetUndefBooleanConstant();
+      [[fallthrough]];
+    case ISD::SETOGT:
+      return getBoolConstant(R == APFloat::cmpGreaterThan, dl, VT, OpVT);
+    case ISD::SETLE:
+      if (R == APFloat::cmpUnordered)
+        return GetUndefBooleanConstant();
+      [[fallthrough]];
+    case ISD::SETOLE:
+      return getBoolConstant(
+          R == APFloat::cmpLessThan || R == APFloat::cmpEqual, dl, VT, OpVT);
+    case ISD::SETGE:
+      if (R == APFloat::cmpUnordered)
+        return GetUndefBooleanConstant();
+      [[fallthrough]];
+    case ISD::SETOGE:
+      return getBoolConstant(
+          R == APFloat::cmpGreaterThan || R == APFloat::cmpEqual, dl, VT, OpVT);
+    case ISD::SETO:
+      return getBoolConstant(R != APFloat::cmpUnordered, dl, VT, OpVT);
+    case ISD::SETUO:
+      return getBoolConstant(R == APFloat::cmpUnordered, dl, VT, OpVT);
+    case ISD::SETUEQ:
+      return getBoolConstant(
+          R == APFloat::cmpUnordered || R == APFloat::cmpEqual, dl, VT, OpVT);
+    case ISD::SETUNE:
+      return getBoolConstant(R != APFloat::cmpEqual, dl, VT, OpVT);
+    case ISD::SETULT:
+      return getBoolConstant(R == APFloat::cmpUnordered ||
+                                 R == APFloat::cmpLessThan,
+                             dl, VT, OpVT);
+    case ISD::SETUGT:
+      return getBoolConstant(R == APFloat::cmpGreaterThan ||
+                                 R == APFloat::cmpUnordered,
+                             dl, VT, OpVT);
+    case ISD::SETULE:
+      return getBoolConstant(R != APFloat::cmpGreaterThan, dl, VT, OpVT);
+    case ISD::SETUGE:
+      return getBoolConstant(R != APFloat::cmpLessThan, dl, VT, OpVT);
     }
   } else if (N1CFP && OpVT.isSimple() && !N2.isUndef()) {
     // Ensure that the constant occurs on the RHS.
@@ -3135,8 +3168,8 @@ bool SelectionDAG::isSplatValue(SDValue V, bool AllowUndefs) const {
   // Since the number of lanes in a scalable vector is unknown at compile time,
   // we track one bit which is implicitly broadcast to all lanes.  This means
   // that all lanes in a scalable vector are considered demanded.
-  APInt DemandedElts
-    = APInt::getAllOnes(VT.isScalableVector() ? 1 : VT.getVectorNumElements());
+  APInt DemandedElts =
+      APInt::getAllOnes(VT.isScalableVector() ? 1 : VT.getVectorNumElements());
   return isSplatValue(V, DemandedElts, UndefElts) &&
          (AllowUndefs || !UndefElts);
 }
@@ -3149,11 +3182,11 @@ SDValue SelectionDAG::getSplatSourceVector(SDValue V, int &SplatIdx) {
   switch (Opcode) {
   default: {
     APInt UndefElts;
-    // Since the number of lanes in a scalable vector is unknown at compile time,
-    // we track one bit which is implicitly broadcast to all lanes.  This means
-    // that all lanes in a scalable vector are considered demanded.
-    APInt DemandedElts
-      = APInt::getAllOnes(VT.isScalableVector() ? 1 : VT.getVectorNumElements());
+    // Since the number of lanes in a scalable vector is unknown at compile
+    // time, we track one bit which is implicitly broadcast to all lanes.  This
+    // means that all lanes in a scalable vector are considered demanded.
+    APInt DemandedElts = APInt::getAllOnes(
+        VT.isScalableVector() ? 1 : VT.getVectorNumElements());
 
     if (isSplatValue(V, DemandedElts, UndefElts)) {
       if (VT.isScalableVector()) {
@@ -3345,7 +3378,7 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
                                          unsigned Depth) const {
   unsigned BitWidth = Op.getScalarValueSizeInBits();
 
-  KnownBits Known(BitWidth);   // Don't know anything.
+  KnownBits Known(BitWidth); // Don't know anything.
 
   if (auto OptAPInt = Op->bitcastToAPInt()) {
     // We know all of the bits for a constant!
@@ -3353,7 +3386,7 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
   }
 
   if (Depth >= MaxRecursionDepth)
-    return Known;  // Limit search depth.
+    return Known; // Limit search depth.
 
   KnownBits Known2;
   unsigned NumElts = DemandedElts.getBitWidth();
@@ -3364,7 +3397,7 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
          "Unexpected vector size");
 
   if (!DemandedElts)
-    return Known;  // No demanded elts, better to assume we don't know anything.
+    return Known; // No demanded elts, better to assume we don't know anything.
 
   unsigned Opcode = Op.getOpcode();
   switch (Opcode) {
@@ -3599,8 +3632,7 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
           SubDemandedElts.setBit(i * SubScale);
 
       for (unsigned i = 0; i != SubScale; ++i) {
-        Known2 = computeKnownBits(N0, SubDemandedElts.shl(i),
-                         Depth + 1);
+        Known2 = computeKnownBits(N0, SubDemandedElts.shl(i), Depth + 1);
         unsigned Shifts = IsLE ? i : SubScale - 1 - i;
         Known.insertBits(Known2, SubBitWidth * Shifts);
       }
@@ -3663,8 +3695,7 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
     // with itself is non-negative. Only do this if we didn't already computed
     // the opposite value for the sign bit.
     if (Op->getFlags().hasNoSignedWrap() &&
-        Op.getOperand(0) == Op.getOperand(1) &&
-        !Known.isNegative())
+        Op.getOperand(0) == Op.getOperand(1) && !Known.isNegative())
       Known.makeNonNegative();
     break;
   }
@@ -3747,21 +3778,21 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
   }
   case ISD::SELECT:
   case ISD::VSELECT:
-    Known = computeKnownBits(Op.getOperand(2), DemandedElts, Depth+1);
+    Known = computeKnownBits(Op.getOperand(2), DemandedElts, Depth + 1);
     // If we don't know any bits, early out.
     if (Known.isUnknown())
       break;
-    Known2 = computeKnownBits(Op.getOperand(1), DemandedElts, Depth+1);
+    Known2 = computeKnownBits(Op.getOperand(1), DemandedElts, Depth + 1);
 
     // Only known if known in both the LHS and RHS.
     Known = Known.intersectWith(Known2);
     break;
   case ISD::SELECT_CC:
-    Known = computeKnownBits(Op.getOperand(3), DemandedElts, Depth+1);
+    Known = computeKnownBits(Op.getOperand(3), DemandedElts, Depth + 1);
     // If we don't know any bits, early out.
     if (Known.isUnknown())
       break;
-    Known2 = computeKnownBits(Op.getOperand(2), DemandedElts, Depth+1);
+    Known2 = computeKnownBits(Op.getOperand(2), DemandedElts, Depth + 1);
 
     // Only known if known in both the LHS and RHS.
     Known = Known.intersectWith(Known2);
@@ -3843,7 +3874,8 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
     break;
   case ISD::FSHL:
   case ISD::FSHR:
-    if (ConstantSDNode *C = isConstOrConstSplat(Op.getOperand(2), DemandedElts)) {
+    if (ConstantSDNode *C =
+            isConstOrConstSplat(Op.getOperand(2), DemandedElts)) {
       unsigned Amt = C->getAPIntValue().urem(BitWidth);
 
       // For fshl, 0-shift returns the 1st arg.
@@ -4102,7 +4134,7 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
     APInt InMask = APInt::getLowBitsSet(BitWidth, VT.getSizeInBits());
     Known = computeKnownBits(Op.getOperand(0), DemandedElts, Depth + 1);
     Known.Zero |= (~InMask);
-    Known.One  &= (~Known.Zero);
+    Known.One &= (~Known.Zero);
     break;
   }
   case ISD::AssertAlign: {
@@ -4241,12 +4273,13 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
     break;
   }
   case ISD::EXTRACT_ELEMENT: {
-    Known = computeKnownBits(Op.getOperand(0), Depth+1);
+    Known = computeKnownBits(Op.getOperand(0), Depth + 1);
     const unsigned Index = Op.getConstantOperandVal(1);
     const unsigned EltBitWidth = Op.getValueSizeInBits();
 
     // Remove low part of known bits mask
-    Known.Zero = Known.Zero.getHiBits(Known.getBitWidth() - Index * EltBitWidth);
+    Known.Zero =
+        Known.Zero.getHiBits(Known.getBitWidth() - Index * EltBitWidth);
     Known.One = Known.One.getHiBits(Known.getBitWidth() - Index * EltBitWidth);
 
     // Remove high part of known bit mask
@@ -4515,7 +4548,8 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
 }
 
 /// Convert ConstantRange OverflowResult into SelectionDAG::OverflowKind.
-static SelectionDAG::OverflowKind mapOverflowResult(ConstantRange::OverflowResult OR) {
+static SelectionDAG::OverflowKind
+mapOverflowResult(ConstantRange::OverflowResult OR) {
   switch (OR) {
   case ConstantRange::OverflowResult::MayOverflow:
     return SelectionDAG::OFK_Sometime;
@@ -4806,20 +4840,21 @@ unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, const APInt &DemandedElts,
   }
 
   if (Depth >= MaxRecursionDepth)
-    return 1;  // Limit search depth.
+    return 1; // Limit search depth.
 
   if (!DemandedElts)
-    return 1;  // No demanded elts, better to assume we don't know anything.
+    return 1; // No demanded elts, better to assume we don't know anything.
 
   unsigned Opcode = Op.getOpcode();
   switch (Opcode) {
-  default: break;
+  default:
+    break;
   case ISD::AssertSext:
     Tmp = cast<VTSDNode>(Op.getOperand(1))->getVT().getSizeInBits();
-    return VTBits-Tmp+1;
+    return VTBits - Tmp + 1;
   case ISD::AssertZext:
     Tmp = cast<VTSDNode>(Op.getOperand(1))->getVT().getSizeInBits();
-    return VTBits-Tmp;
+    return VTBits - Tmp;
   case ISD::FREEZE:
     if (isGuaranteedNotToBeUndefOrPoison(Op.getOperand(0), DemandedElts,
                                          /*PoisonOnly=*/false))
@@ -4950,12 +4985,12 @@ unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, const APInt &DemandedElts,
     return VTBits - Tmp + 1;
   case ISD::SIGN_EXTEND:
     Tmp = VTBits - Op.getOperand(0).getScalarValueSizeInBits();
-    return ComputeNumSignBits(Op.getOperand(0), DemandedElts, Depth+1) + Tmp;
+    return ComputeNumSignBits(Op.getOperand(0), DemandedElts, Depth + 1) + Tmp;
   case ISD::SIGN_EXTEND_INREG:
     // Max of the input and what this extends.
     Tmp = cast<VTSDNode>(Op.getOperand(1))->getVT().getScalarSizeInBits();
-    Tmp = VTBits-Tmp+1;
-    Tmp2 = ComputeNumSignBits(Op.getOperand(0), DemandedElts, Depth+1);
+    Tmp = VTBits - Tmp + 1;
+    Tmp2 = ComputeNumSignBits(Op.getOperand(0), DemandedElts, Depth + 1);
     return std::max(Tmp, Tmp2);
   case ISD::SIGN_EXTEND_VECTOR_INREG: {
     if (VT.isScalableVector())
@@ -4964,7 +4999,7 @@ unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, const APInt &DemandedElts,
     EVT SrcVT = Src.getValueType();
     APInt DemandedSrcElts = DemandedElts.zext(SrcVT.getVectorNumElements());
     Tmp = VTBits - SrcVT.getScalarSizeInBits();
-    return ComputeNumSignBits(Src, DemandedSrcElts, Depth+1) + Tmp;
+    return ComputeNumSignBits(Src, DemandedSrcElts, Depth + 1) + Tmp;
   }
   case ISD::SRA:
     Tmp = ComputeNumSignBits(Op.getOperand(0), DemandedElts, Depth + 1);
@@ -5005,11 +5040,11 @@ unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, const APInt &DemandedElts,
     break;
   case ISD::AND:
   case ISD::OR:
-  case ISD::XOR:    // NOT is handled here.
+  case ISD::XOR: // NOT is handled here.
     // Logical binary ops preserve the number of sign bits at the worst.
-    Tmp = ComputeNumSignBits(Op.getOperand(0), DemandedElts, Depth+1);
+    Tmp = ComputeNumSignBits(Op.getOperand(0), DemandedElts, Depth + 1);
     if (Tmp != 1) {
-      Tmp2 = ComputeNumSignBits(Op.getOperand(1), DemandedElts, Depth+1);
+      Tmp2 = ComputeNumSignBits(Op.getOperand(1), DemandedElts, Depth + 1);
       FirstAnswer = std::min(Tmp, Tmp2);
       // We computed what we know about the sign bits as our first
       // answer. Now proceed to the generic code that uses
@@ -5019,14 +5054,16 @@ unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, const APInt &DemandedElts,
 
   case ISD::SELECT:
   case ISD::VSELECT:
-    Tmp = ComputeNumSignBits(Op.getOperand(1), DemandedElts, Depth+1);
-    if (Tmp == 1) return 1;  // Early out.
-    Tmp2 = ComputeNumSignBits(Op.getOperand(2), DemandedElts, Depth+1);
+    Tmp = ComputeNumSignBits(Op.getOperand(1), DemandedElts, Depth + 1);
+    if (Tmp == 1)
+      return 1; // Early out.
+    Tmp2 = ComputeNumSignBits(Op.getOperand(2), DemandedElts, Depth + 1);
     return std::min(Tmp, Tmp2);
   case ISD::SELECT_CC:
-    Tmp = ComputeNumSignBits(Op.getOperand(2), DemandedElts, Depth+1);
-    if (Tmp == 1) return 1;  // Early out.
-    Tmp2 = ComputeNumSignBits(Op.getOperand(3), DemandedElts, Depth+1);
+    Tmp = ComputeNumSignBits(Op.getOperand(2), DemandedElts, Depth + 1);
+    if (Tmp == 1)
+      return 1; // Early out.
+    Tmp2 = ComputeNumSignBits(Op.getOperand(3), DemandedElts, Depth + 1);
     return std::min(Tmp, Tmp2);
 
   case ISD::SMIN:
@@ -5052,7 +5089,7 @@ unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, const APInt &DemandedElts,
     // Fallback - just get the minimum number of sign bits of the operands.
     Tmp = ComputeNumSignBits(Op.getOperand(0), DemandedElts, Depth + 1);
     if (Tmp == 1)
-      return 1;  // Early out.
+      return 1; // Early out.
     Tmp2 = ComputeNumSignBits(Op.getOperand(1), DemandedElts, Depth + 1);
     return std::min(Tmp, Tmp2);
   }
@@ -5060,7 +5097,7 @@ unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, const APInt &DemandedElts,
   case ISD::UMAX:
     Tmp = ComputeNumSignBits(Op.getOperand(0), DemandedElts, Depth + 1);
     if (Tmp == 1)
-      return 1;  // Early out.
+      return 1; // Early out.
     Tmp2 = ComputeNumSignBits(Op.getOperand(1), DemandedElts, Depth + 1);
     return std::min(Tmp, Tmp2);
   case ISD::SSUBO_CARRY:
@@ -5116,14 +5153,16 @@ unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, const APInt &DemandedElts,
 
       // If we aren't rotating out all of the known-in sign bits, return the
       // number that are left.  This handles rotl(sext(x), 1) for example.
-      if (Tmp > (RotAmt + 1)) return (Tmp - RotAmt);
+      if (Tmp > (RotAmt + 1))
+        return (Tmp - RotAmt);
     }
     break;
   case ISD::ADD:
   case ISD::ADDC:
     // TODO: Move Operand 1 check before Operand 0 check
     Tmp = ComputeNumSignBits(Op.getOperand(0), DemandedElts, Depth + 1);
-    if (Tmp == 1) return 1; // Early out.
+    if (Tmp == 1)
+      return 1; // Early out.
 
     // Special case decrementing a value (ADD X, -1):
     if (ConstantSDNode *CRHS =
@@ -5144,14 +5183,16 @@ unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, const APInt &DemandedElts,
       }
 
     Tmp2 = ComputeNumSignBits(Op.getOperand(1), DemandedElts, Depth + 1);
-    if (Tmp2 == 1) return 1; // Early out.
+    if (Tmp2 == 1)
+      return 1; // Early out.
 
     // Add can have at most one carry bit.  Thus we know that the output
     // is, at worst, one more bit than the inputs.
     return std::min(Tmp, Tmp2) - 1;
   case ISD::SUB:
     Tmp2 = ComputeNumSignBits(Op.getOperand(1), DemandedElts, Depth + 1);
-    if (Tmp2 == 1) return 1; // Early out.
+    if (Tmp2 == 1)
+      return 1; // Early out.
 
     // Handle NEG.
     if (ConstantSDNode *CLHS =
@@ -5175,7 +5216,8 @@ unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, const APInt &DemandedElts,
     // Sub can have at most one carry bit.  Thus we know that the output
     // is, at worst, one more bit than the inputs.
     Tmp = ComputeNumSignBits(Op.getOperand(0), DemandedElts, Depth + 1);
-    if (Tmp == 1) return 1; // Early out.
+    if (Tmp == 1)
+      return 1; // Early out.
     return std::min(Tmp, Tmp2) - 1;
   case ISD::MUL: {
     // The output of the Mul can be at most twice the valid bits in the inputs.
@@ -5213,7 +5255,7 @@ unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, const APInt &DemandedElts,
   case ISD::EXTRACT_ELEMENT: {
     if (VT.isScalableVector())
       break;
-    const int KnownSign = ComputeNumSignBits(Op.getOperand(0), Depth+1);
+    const int KnownSign = ComputeNumSignBits(Op.getOperand(0), Depth + 1);
     const int BitWidth = Op.getValueSizeInBits();
     const int Items = Op.getOperand(0).getValueSizeInBits() / BitWidth;
 
@@ -5463,15 +5505,13 @@ unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, const APInt &DemandedElts,
   }
 
   // Allow the target to implement this method for its nodes.
-  if (Opcode >= ISD::BUILTIN_OP_END ||
-      Opcode == ISD::INTRINSIC_WO_CHAIN ||
-      Opcode == ISD::INTRINSIC_W_CHAIN ||
-      Opcode == ISD::INTRINSIC_VOID) {
+  if (Opcode >= ISD::BUILTIN_OP_END || Opcode == ISD::INTRINSIC_WO_CHAIN ||
+      Opcode == ISD::INTRINSIC_W_CHAIN || Opcode == ISD::INTRINSIC_VOID) {
     // TODO: This can probably be removed once target code is audited.  This
     // is here purely to reduce patch size and review complexity.
     if (!VT.isScalableVector()) {
       unsigned NumBits =
-        TLI->ComputeNumSignBitsForTargetNode(Op, DemandedElts, *this, Depth);
+          TLI->ComputeNumSignBitsForTargetNode(Op, DemandedElts, *this, Depth);
       if (NumBits > 1)
         FirstAnswer = std::max(FirstAnswer, NumBits);
     }
@@ -6135,8 +6175,7 @@ bool SelectionDAG::isKnownNeverNaN(SDValue Op, const APInt &DemandedElts,
 }
 
 bool SelectionDAG::isKnownNeverZeroFloat(SDValue Op) const {
-  assert(Op.getValueType().isFloatingPoint() &&
-         "Floating point type expected");
+  assert(Op.getValueType().isFloatingPoint() && "Floating point type expected");
 
   // If the value is a constant, we can obviously see if it is a zero or not.
   return ISD::matchUnaryFpPredicate(
@@ -6289,7 +6328,7 @@ bool SelectionDAG::isKnownNeverZero(SDValue Op, const APInt &DemandedElts,
     // div exact can only produce a zero if the dividend is zero.
     // TODO: For udiv this is also true if Op1 u<= Op0
     if (Op->getFlags().hasExact())
-      return isKnownNeverZero(Op.getOperand(0), Depth + 1);
+      return isKnownNeverZero(Op.getOperand(0), DemandedElts, Depth + 1);
     break;
 
   case ISD::ADD:
@@ -6398,12 +6437,14 @@ bool SelectionDAG::canIgnoreSignBitOfZero(SDValue Op) const {
 
 bool SelectionDAG::isEqualTo(SDValue A, SDValue B) const {
   // Check the obvious case.
-  if (A == B) return true;
+  if (A == B)
+    return true;
 
   // For negative and positive zero.
   if (const ConstantFPSDNode *CA = dyn_cast<ConstantFPSDNode>(A))
     if (const ConstantFPSDNode *CB = dyn_cast<ConstantFPSDNode>(B))
-      if (CA->isZero() && CB->isZero()) return true;
+      if (CA->isZero() && CB->isZero())
+        return true;
 
   // Otherwise they may not be equal.
   return false;
@@ -6480,8 +6521,7 @@ static SDValue FoldSTEP_VECTOR(const SDLoc &DL, EVT VT, SDValue Step,
   return SDValue();
 }
 
-static SDValue FoldBUILD_VECTOR(const SDLoc &DL, EVT VT,
-                                ArrayRef<SDValue> Ops,
+static SDValue FoldBUILD_VECTOR(const SDLoc &DL, EVT VT, ArrayRef<SDValue> Ops,
                                 SelectionDAG &DAG) {
   int NumOps = Ops.size();
   assert(NumOps != 0 && "Can't build an empty vector!");
@@ -6517,8 +6557,7 @@ static SDValue FoldBUILD_VECTOR(const SDLoc &DL, EVT VT,
 /// Try to simplify vector concatenation to an input value, undef, or build
 /// vector.
 static SDValue foldCONCAT_VECTORS(const SDLoc &DL, EVT VT,
-                                  ArrayRef<SDValue> Ops,
-                                  SelectionDAG &DAG) {
+                                  ArrayRef<SDValue> Ops, SelectionDAG &DAG) {
   assert(!Ops.empty() && "Can't concatenate an empty list of vectors!");
   assert(llvm::all_of(Ops,
                       [Ops](SDValue Op) {
@@ -6694,7 +6733,7 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
   case ISD::TokenFactor:
   case ISD::MERGE_VALUES:
   case ISD::CONCAT_VECTORS:
-    return N1;         // Factor, merge or concat of one node?  No need.
+    return N1; // Factor, merge or concat of one node?  No need.
   case ISD::BUILD_VECTOR: {
     // Attempt to simplify BUILD_VECTOR.
     SDValue Ops[] = {N1};
@@ -6702,11 +6741,13 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
       return V;
     break;
   }
-  case ISD::FP_ROUND: llvm_unreachable("Invalid method to make FP_ROUND node");
+  case ISD::FP_ROUND:
+    llvm_unreachable("Invalid method to make FP_ROUND node");
   case ISD::FP_EXTEND:
     assert(VT.isFloatingPoint() && N1.getValueType().isFloatingPoint() &&
            "Invalid FP cast!");
-    if (N1.getValueType() == VT) return N1;  // noop conversion.
+    if (N1.getValueType() == VT)
+      return N1; // noop conversion.
     assert((!VT.isVector() || VT.getVectorElementCount() ==
                                   N1.getValueType().getVectorElementCount()) &&
            "Vector element count mismatch!");
@@ -6731,7 +6772,8 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
     assert(VT.isVector() == N1.getValueType().isVector() &&
            "SIGN_EXTEND result type type should be vector iff the operand "
            "type is vector!");
-    if (N1.getValueType() == VT) return N1;   // noop extension
+    if (N1.getValueType() == VT)
+      return N1; // noop extension
     assert((!VT.isVector() || VT.getVectorElementCount() ==
                                   N1.getValueType().getVectorElementCount()) &&
            "Vector element count mismatch!");
@@ -6772,7 +6814,8 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
     assert(VT.isVector() == N1.getValueType().isVector() &&
            "ZERO_EXTEND result type type should be vector iff the operand "
            "type is vector!");
-    if (N1.getValueType() == VT) return N1;   // noop extension
+    if (N1.getValueType() == VT)
+      return N1; // noop extension
     assert((!VT.isVector() || VT.getVectorElementCount() ==
                                   N1.getValueType().getVectorElementCount()) &&
            "Vector element count mismatch!");
@@ -6817,7 +6860,8 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
     assert(VT.isVector() == N1.getValueType().isVector() &&
            "ANY_EXTEND result type type should be vector iff the operand "
            "type is vector!");
-    if (N1.getValueType() == VT) return N1;   // noop extension
+    if (N1.getValueType() == VT)
+      return N1; // noop extension
     assert((!VT.isVector() || VT.getVectorElementCount() ==
                                   N1.getValueType().getVectorElementCount()) &&
            "Vector element count mismatch!");
@@ -6849,7 +6893,8 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
     assert(VT.isVector() == N1.getValueType().isVector() &&
            "TRUNCATE result type type should be vector iff the operand "
            "type is vector!");
-    if (N1.getValueType() == VT) return N1;   // noop truncate
+    if (N1.getValueType() == VT)
+      return N1; // noop truncate
     assert((!VT.isVector() || VT.getVectorElementCount() ==
                                   N1.getValueType().getVectorElementCount()) &&
            "Vector element count mismatch!");
@@ -6909,7 +6954,8 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
   case ISD::BITCAST:
     assert(VT.getSizeInBits() == N1.getValueSizeInBits() &&
            "Cannot BITCAST between types of different sizes!");
-    if (VT == N1.getValueType()) return N1;   // noop conversion.
+    if (VT == N1.getValueType())
+      return N1;                  // noop conversion.
     if (OpOpcode == ISD::BITCAST) // bitconv(bitconv(x)) -> bitconv(x)
       return getNode(ISD::BITCAST, DL, VT, N1.getOperand(0));
     if (N1.isUndef())
@@ -7016,27 +7062,48 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
 static std::optional<APInt> FoldValue(unsigned Opcode, const APInt &C1,
                                       const APInt &C2) {
   switch (Opcode) {
-  case ISD::ADD:  return C1 + C2;
-  case ISD::SUB:  return C1 - C2;
-  case ISD::MUL:  return C1 * C2;
-  case ISD::AND:  return C1 & C2;
-  case ISD::OR:   return C1 | C2;
-  case ISD::XOR:  return C1 ^ C2;
-  case ISD::SHL:  return C1 << C2;
-  case ISD::SRL:  return C1.lshr(C2);
-  case ISD::SRA:  return C1.ashr(C2);
-  case ISD::ROTL: return C1.rotl(C2);
-  case ISD::ROTR: return C1.rotr(C2);
-  case ISD::SMIN: return C1.sle(C2) ? C1 : C2;
-  case ISD::SMAX: return C1.sge(C2) ? C1 : C2;
-  case ISD::UMIN: return C1.ule(C2) ? C1 : C2;
-  case ISD::UMAX: return C1.uge(C2) ? C1 : C2;
-  case ISD::SADDSAT: return C1.sadd_sat(C2);
-  case ISD::UADDSAT: return C1.uadd_sat(C2);
-  case ISD::SSUBSAT: return C1.ssub_sat(C2);
-  case ISD::USUBSAT: return C1.usub_sat(C2);
-  case ISD::SSHLSAT: return C1.sshl_sat(C2);
-  case ISD::USHLSAT: return C1.ushl_sat(C2);
+  case ISD::ADD:
+    return C1 + C2;
+  case ISD::SUB:
+    return C1 - C2;
+  case ISD::MUL:
+    return C1 * C2;
+  case ISD::AND:
+    return C1 & C2;
+  case ISD::OR:
+    return C1 | C2;
+  case ISD::XOR:
+    return C1 ^ C2;
+  case ISD::SHL:
+    return C1 << C2;
+  case ISD::SRL:
+    return C1.lshr(C2);
+  case ISD::SRA:
+    return C1.ashr(C2);
+  case ISD::ROTL:
+    return C1.rotl(C2);
+  case ISD::ROTR:
+    return C1.rotr(C2);
+  case ISD::SMIN:
+    return C1.sle(C2) ? C1 : C2;
+  case ISD::SMAX:
+    return C1.sge(C2) ? C1 : C2;
+  case ISD::UMIN:
+    return C1.ule(C2) ? C1 : C2;
+  case ISD::UMAX:
+    return C1.uge(C2) ? C1 : C2;
+  case ISD::SADDSAT:
+    return C1.sadd_sat(C2);
+  case ISD::UADDSAT:
+    return C1.uadd_sat(C2);
+  case ISD::SSUBSAT:
+    return C1.ssub_sat(C2);
+  case ISD::USUBSAT:
+    return C1.usub_sat(C2);
+  case ISD::SSHLSAT:
+    return C1.sshl_sat(C2);
+  case ISD::USHLSAT:
+    return C1.ushl_sat(C2);
   case ISD::UDIV:
     if (!C2.getBoolValue())
       break;
@@ -7109,8 +7176,11 @@ SDValue SelectionDAG::FoldSymbolOffset(unsigned Opcode, EVT VT,
   case ISD::ADD:
   case ISD::PTRADD:
     break;
-  case ISD::SUB: Offset = -uint64_t(Offset); break;
-  default: return SDValue();
+  case ISD::SUB:
+    Offset = -uint64_t(Offset);
+    break;
+  default:
+    return SDValue();
   }
   return getGlobalAddress(GA->getGlobal(), SDLoc(C2), VT,
                           GA->getOffset() + uint64_t(Offset));
@@ -7130,9 +7200,9 @@ bool SelectionDAG::isUndef(unsigned Opcode, ArrayRef<SDValue> Ops) {
       return true;
 
     return ISD::isBuildVectorOfConstantSDNodes(Divisor.getNode()) &&
-           llvm::any_of(Divisor->op_values(),
-                        [](SDValue V) { return V.isUndef() ||
-                                        isNullConstant(V); });
+           llvm::any_of(Divisor->op_values(), [](SDValue V) {
+             return V.isUndef() || isNullConstant(V);
+           });
     // TODO: Handle signed overflow.
   }
   // TODO: Handle oversized shifts.
@@ -7661,11 +7731,12 @@ SDValue SelectionDAG::foldConstantFPMath(unsigned Opcode, const SDLoc &DL,
       return getConstantFP(minimumnum(C1, C2), DL, VT);
     case ISD::FMAXIMUMNUM:
       return getConstantFP(maximumnum(C1, C2), DL, VT);
-    default: break;
+    default:
+      break;
     }
   }
   if (N1CFP && Opcode == ISD::FP_ROUND) {
-    APFloat C1 = N1CFP->getValueAPF();    // make copy
+    APFloat C1 = N1CFP->getValueAPF(); // make copy
     bool Unused;
     // This can return overflow, underflow, or inexact; we don't care.
     // FIXME need to be more flexible about rounding mode.
@@ -7829,8 +7900,7 @@ void SelectionDAG::canonicalizeCommutativeBinop(unsigned Opcode, SDValue &N1,
 SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
                               SDValue N1, SDValue N2, const SDNodeFlags Flags) {
   assert(N1.getOpcode() != ISD::DELETED_NODE &&
-         N2.getOpcode() != ISD::DELETED_NODE &&
-         "Operand is DELETED_NODE!");
+         N2.getOpcode() != ISD::DELETED_NODE && "Operand is DELETED_NODE!");
 
   canonicalizeCommutativeBinop(Opcode, N1, N2);
 
@@ -7843,14 +7913,18 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
       isConstOrConstSplat(N2, /*AllowUndefs*/ false, /*AllowTruncation*/ true);
 
   switch (Opcode) {
-  default: break;
+  default:
+    break;
   case ISD::TokenFactor:
     assert(VT == MVT::Other && N1.getValueType() == MVT::Other &&
            N2.getValueType() == MVT::Other && "Invalid token factor!");
     // Fold trivial token factors.
-    if (N1.getOpcode() == ISD::EntryToken) return N2;
-    if (N2.getOpcode() == ISD::EntryToken) return N1;
-    if (N1 == N2) return N1;
+    if (N1.getOpcode() == ISD::EntryToken)
+      return N2;
+    if (N2.getOpcode() == ISD::EntryToken)
+      return N1;
+    if (N1 == N2)
+      return N1;
     break;
   case ISD::BUILD_VECTOR: {
     // Attempt to simplify BUILD_VECTOR.
@@ -7867,8 +7941,8 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
   }
   case ISD::AND:
     assert(VT.isInteger() && "This operator does not apply to FP types!");
-    assert(N1.getValueType() == N2.getValueType() &&
-           N1.getValueType() == VT && "Binary operator types must match!");
+    assert(N1.getValueType() == N2.getValueType() && N1.getValueType() == VT &&
+           "Binary operator types must match!");
     // (X & 0) -> 0.  This commonly occurs when legalizing i64 values, so it's
     // worth handling here.
     if (N2CV && N2CV->isZero())
@@ -7882,8 +7956,8 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
   case ISD::PTRADD:
   case ISD::SUB:
     assert(VT.isInteger() && "This operator does not apply to FP types!");
-    assert(N1.getValueType() == N2.getValueType() &&
-           N1.getValueType() == VT && "Binary operator types must match!");
+    assert(N1.getValueType() == N2.getValueType() && N1.getValueType() == VT &&
+           "Binary operator types must match!");
     // The equal operand types requirement is unnecessarily strong for PTRADD.
     // However, the SelectionDAGBuilder does not generate PTRADDs with different
     // operand types, and we'd need to re-implement GEP's non-standard wrapping
@@ -7908,8 +7982,8 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
     break;
   case ISD::MUL:
     assert(VT.isInteger() && "This operator does not apply to FP types!");
-    assert(N1.getValueType() == N2.getValueType() &&
-           N1.getValueType() == VT && "Binary operator types must match!");
+    assert(N1.getValueType() == N2.getValueType() && N1.getValueType() == VT &&
+           "Binary operator types must match!");
     if (VT.getScalarType() == MVT::i1)
       return getNode(ISD::AND, DL, VT, N1, N2);
     if (N2CV && N2CV->isZero())
@@ -7931,8 +8005,8 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
   case ISD::UADDSAT:
   case ISD::USUBSAT:
     assert(VT.isInteger() && "This operator does not apply to FP types!");
-    assert(N1.getValueType() == N2.getValueType() &&
-           N1.getValueType() == VT && "Binary operator types must match!");
+    assert(N1.getValueType() == N2.getValueType() && N1.getValueType() == VT &&
+           "Binary operator types must match!");
     if (VT.getScalarType() == MVT::i1) {
       // fold (add_sat x, y) -> (or x, y) for bool types.
       if (Opcode == ISD::SADDSAT || Opcode == ISD::UADDSAT)
@@ -7958,30 +8032,30 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
   case ISD::AVGCEILS:
   case ISD::AVGCEILU:
     assert(VT.isInteger() && "This operator does not apply to FP types!");
-    assert(N1.getValueType() == N2.getValueType() &&
-           N1.getValueType() == VT && "Binary operator types must match!");
+    assert(N1.getValueType() == N2.getValueType() && N1.getValueType() == VT &&
+           "Binary operator types must match!");
     break;
   case ISD::ABDS:
   case ISD::ABDU:
     assert(VT.isInteger() && "This operator does not apply to FP types!");
-    assert(N1.getValueType() == N2.getValueType() &&
-           N1.getValueType() == VT && "Binary operator types must match!");
+    assert(N1.getValueType() == N2.getValueType() && N1.getValueType() == VT &&
+           "Binary operator types must match!");
     if (VT.getScalarType() == MVT::i1)
       return getNode(ISD::XOR, DL, VT, N1, N2);
     break;
   case ISD::SMIN:
   case ISD::UMAX:
     assert(VT.isInteger() && "This operator does not apply to FP types!");
-    assert(N1.getValueType() == N2.getValueType() &&
-           N1.getValueType() == VT && "Binary operator types must match!");
+    assert(N1.getValueType() == N2.getValueType() && N1.getValueType() == VT &&
+           "Binary operator types must match!");
     if (VT.getScalarType() == MVT::i1)
       return getNode(ISD::OR, DL, VT, N1, N2);
     break;
   case ISD::SMAX:
   case ISD::UMIN:
     assert(VT.isInteger() && "This operator does not apply to FP types!");
-    assert(N1.getValueType() == N2.getValueType() &&
-           N1.getValueType() == VT && "Binary operator types must match!");
+    assert(N1.getValueType() == N2.getValueType() && N1.getValueType() == VT &&
+           "Binary operator types must match!");
     if (VT.getScalarType() == MVT::i1)
       return getNode(ISD::AND, DL, VT, N1, N2);
     break;
@@ -7991,16 +8065,14 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
   case ISD::FDIV:
   case ISD::FREM:
     assert(VT.isFloatingPoint() && "This operator only applies to FP types!");
-    assert(N1.getValueType() == N2.getValueType() &&
-           N1.getValueType() == VT && "Binary operator types must match!");
+    assert(N1.getValueType() == N2.getValueType() && N1.getValueType() == VT &&
+           "Binary operator types must match!");
     if (SDValue V = simplifyFPBinop(Opcode, N1, N2, Flags))
       return V;
     break;
-  case ISD::FCOPYSIGN:   // N1 and result must match.  N1/N2 need not match.
-    assert(N1.getValueType() == VT &&
-           N1.getValueType().isFloatingPoint() &&
-           N2.getValueType().isFloatingPoint() &&
-           "Invalid FCOPYSIGN!");
+  case ISD::FCOPYSIGN: // N1 and result must match.  N1/N2 need not match.
+    assert(N1.getValueType() == VT && N1.getValueType().isFloatingPoint() &&
+           N2.getValueType().isFloatingPoint() && "Invalid FCOPYSIGN!");
     break;
   case ISD::SHL:
     if (N2C && (N1.getOpcode() == ISD::VSCALE) && Flags.hasNoSignedWrap()) {
@@ -8045,7 +8117,8 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
            VT.bitsLE(N1.getValueType()) && N2C &&
            (N2C->getZExtValue() == 0 || N2C->getZExtValue() == 1) &&
            N2.getOpcode() == ISD::TargetConstant && "Invalid FP_ROUND!");
-    if (N1.getValueType() == VT) return N1;  // noop conversion.
+    if (N1.getValueType() == VT)
+      return N1; // noop conversion.
     break;
   case ISD::AssertNoFPClass: {
     assert(N1.getValueType().isFloatingPoint() &&
@@ -8068,7 +8141,8 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
            "AssertSExt/AssertZExt type should be the vector element type "
            "rather than the vector type!");
     assert(EVT.bitsLE(VT.getScalarType()) && "Not extending!");
-    if (VT.getScalarType() == EVT) return N1; // noop assertion.
+    if (VT.getScalarType() == EVT)
+      return N1; // noop assertion.
     break;
   }
   case ISD::SIGN_EXTEND_INREG: {
@@ -8083,7 +8157,8 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
             EVT.getVectorElementCount() == VT.getVectorElementCount()) &&
            "Vector element counts must match in SIGN_EXTEND_INREG");
     assert(EVT.getScalarType().bitsLE(VT.getScalarType()) && "Not extending!");
-    if (EVT == VT) return N1;  // Not actually extending
+    if (EVT == VT)
+      return N1; // Not actually extending
     break;
   }
   case ISD::FP_TO_SINT_SAT:
@@ -8164,7 +8239,8 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
           if (VT == N1.getOperand(1).getValueType())
             return N1.getOperand(1);
           if (VT.isFloatingPoint()) {
-            assert(VT.getSizeInBits() > N1.getOperand(1).getValueType().getSizeInBits());
+            assert(VT.getSizeInBits() >
+                   N1.getOperand(1).getValueType().getSizeInBits());
             return getFPExtendOrRound(N1.getOperand(1), DL, VT);
           }
           return getSExtOrTrunc(N1.getOperand(1), DL, VT);
@@ -8192,8 +8268,7 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
     assert(N2C && (unsigned)N2C->getZExtValue() < 2 && "Bad EXTRACT_ELEMENT!");
     assert(!N1.getValueType().isVector() && !VT.isVector() &&
            (N1.getValueType().isInteger() == VT.isInteger()) &&
-           N1.getValueType() != VT &&
-           "Wrong types for EXTRACT_ELEMENT!");
+           N1.getValueType() != VT && "Wrong types for EXTRACT_ELEMENT!");
 
     // EXTRACT_ELEMENT of BUILD_PAIR is often formed while legalize is expanding
     // 64-bit integers into 32-bit parts.  Instead of building the extract of
@@ -8401,8 +8476,7 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
                               const SDNodeFlags Flags) {
   assert(N1.getOpcode() != ISD::DELETED_NODE &&
          N2.getOpcode() != ISD::DELETED_NODE &&
-         N3.getOpcode() != ISD::DELETED_NODE &&
-         "Operand is DELETED_NODE!");
+         N3.getOpcode() != ISD::DELETED_NODE && "Operand is DELETED_NODE!");
   // Perform various simplifications.
   switch (Opcode) {
   case ISD::BUILD_VECTOR: {
@@ -8659,7 +8733,7 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
 SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
                               SDValue N1, SDValue N2, SDValue N3, SDValue N4,
                               const SDNodeFlags Flags) {
-  SDValue Ops[] = { N1, N2, N3, N4 };
+  SDValue Ops[] = {N1, N2, N3, N4};
   return getNode(Opcode, DL, VT, Ops, Flags);
 }
 
@@ -8674,7 +8748,7 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
 SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
                               SDValue N1, SDValue N2, SDValue N3, SDValue N4,
                               SDValue N5, const SDNodeFlags Flags) {
-  SDValue Ops[] = { N1, N2, N3, N4, N5 };
+  SDValue Ops[] = {N1, N2, N3, N4, N5};
   return getNode(Opcode, DL, VT, Ops, Flags);
 }
 
@@ -8719,7 +8793,8 @@ static SDValue getMemsetValue(SDValue Value, EVT VT, SelectionDAG &DAG,
     assert(C->getAPIntValue().getBitWidth() == 8);
     APInt Val = APInt::getSplat(NumBits, C->getAPIntValue());
     if (VT.isInteger()) {
-      bool IsOpaque = VT.getSizeInBits() > 64 ||
+      bool IsOpaque =
+          VT.getSizeInBits() > 64 ||
           !DAG.getTargetLoweringInfo().isLegalStoreImmediate(C->getSExtValue());
       return DAG.getConstant(Val, dl, VT, false, IsOpaque);
     }
@@ -8770,10 +8845,10 @@ static SDValue getMemsetStringVal(EVT VT, const SDLoc &dl, SelectionDAG &DAG,
   APInt Val(NumVTBits, 0);
   if (DAG.getDataLayout().isLittleEndian()) {
     for (unsigned i = 0; i != NumBytes; ++i)
-      Val |= (uint64_t)(unsigned char)Slice[i] << i*8;
+      Val |= (uint64_t)(unsigned char)Slice[i] << i * 8;
   } else {
     for (unsigned i = 0; i != NumBytes; ++i)
-      Val |= (uint64_t)(unsigned char)Slice[i] << (NumVTBytes-i-1)*8;
+      Val |= (uint64_t)(unsigned char)Slice[i] << (NumVTBytes - i - 1) * 8;
   }
 
   // If the "cost" of materializing the integer immediate is less than the cost
@@ -8833,10 +8908,10 @@ static bool shouldLowerMemFuncForSize(const MachineFunction &MF,
   return DAG.shouldOptForSize();
 }
 
-static void chainLoadsAndStoresForMemcpy(SelectionDAG &DAG, const SDLoc &dl,
-                          SmallVector<SDValue, 32> &OutChains, unsigned From,
-                          unsigned To, SmallVector<SDValue, 16> &OutLoadChains,
-                          SmallVector<SDValue, 16> &OutStoreChains) {
+static void chainLoadsAndStoresForMemcpy(
+    SelectionDAG &DAG, const SDLoc &dl, SmallVector<SDValue, 32> &OutChains,
+    unsigned From, unsigned To, SmallVector<SDValue, 16> &OutLoadChains,
+    SmallVector<SDValue, 16> &OutStoreChains) {
   assert(OutLoadChains.size() && "Missing loads in memcpy inlining");
   assert(OutStoreChains.size() && "Missing stores in memcpy inlining");
   SmallVector<SDValue, 16> GluedLoadChains;
@@ -8846,14 +8921,14 @@ static void chainLoadsAndStoresForMemcpy(SelectionDAG &DAG, const SDLoc &dl,
   }
 
   // Chain for all loads.
-  SDValue LoadToken = DAG.getNode(ISD::TokenFactor, dl, MVT::Other,
-                                  GluedLoadChains);
+  SDValue LoadToken =
+      DAG.getNode(ISD::TokenFactor, dl, MVT::Other, GluedLoadChains);
 
   for (unsigned i = From; i < To; ++i) {
     StoreSDNode *ST = dyn_cast<StoreSDNode>(OutStoreChains[i]);
-    SDValue NewStore = DAG.getTruncStore(LoadToken, dl, ST->getValue(),
-                                  ST->getBasePtr(), ST->getMemoryVT(),
-                                  ST->getMemOperand());
+    SDValue NewStore =
+        DAG.getTruncStore(LoadToken, dl, ST->getValue(), ST->getBasePtr(),
+                          ST->getMemoryVT(), ST->getMemOperand());
     OutChains.push_back(NewStore);
   }
 }
@@ -8946,7 +9021,7 @@ static SDValue getMemcpyLoadsAndStores(
     if (VTSize > Size) {
       // Issuing an unaligned load / store pair  that overlaps with the previous
       // pair. Adjust the offset accordingly.
-      assert(i == NumMemOps-1 && i != 0);
+      assert(i == NumMemOps - 1 && i != 0);
       SrcOff -= VTSize - Size;
       DstOff -= VTSize - Size;
     }
@@ -9013,8 +9088,8 @@ static SDValue getMemcpyLoadsAndStores(
     Size -= VTSize;
   }
 
-  unsigned GluedLdStLimit = MaxLdStGlue == 0 ?
-                                TLI.getMaxGluedStoresPerMemcpy() : MaxLdStGlue;
+  unsigned GluedLdStLimit =
+      MaxLdStGlue == 0 ? TLI.getMaxGluedStoresPerMemcpy() : MaxLdStGlue;
   unsigned NumLdStInMemcpy = OutStoreChains.size();
 
   if (NumLdStInMemcpy) {
@@ -9030,11 +9105,10 @@ static SDValue getMemcpyLoadsAndStores(
     } else {
       // Ld/St less than/equal limit set by target.
       if (NumLdStInMemcpy <= GluedLdStLimit) {
-          chainLoadsAndStoresForMemcpy(DAG, dl, OutChains, 0,
-                                        NumLdStInMemcpy, OutLoadChains,
-                                        OutStoreChains);
+        chainLoadsAndStoresForMemcpy(DAG, dl, OutChains, 0, NumLdStInMemcpy,
+                                     OutLoadChains, OutStoreChains);
       } else {
-        unsigned NumberLdChain =  NumLdStInMemcpy / GluedLdStLimit;
+        unsigned NumberLdChain = NumLdStInMemcpy / GluedLdStLimit;
         unsigned RemainingLdStInMemcpy = NumLdStInMemcpy % GluedLdStLimit;
         unsigned GlueIter = 0;
 
@@ -9266,7 +9340,7 @@ static SDValue getMemsetStores(SelectionDAG &DAG, const SDLoc &dl,
     if (VTSize > Size) {
       // Issuing an unaligned load / store pair that overlaps with the previous
       // pair. Adjust the offset accordingly.
-      assert(i == NumMemOps-1 && i != 0);
+      assert(i == NumMemOps - 1 && i != 0);
       DstOff -= VTSize - Size;
     }
 
@@ -9547,7 +9621,7 @@ SDValue SelectionDAG::getMemcpy(
       .setDiscardResult()
       .setTailCall(IsTailCall);
 
-  std::pair<SDValue,SDValue> CallResult = TLI->LowerCallTo(CLI);
+  std::pair<SDValue, SDValue> CallResult = TLI->LowerCallTo(CLI);
   return CallResult.second;
 }
 
@@ -9653,7 +9727,7 @@ SDValue SelectionDAG::getMemmove(SDValue Chain, const SDLoc &dl, SDValue Dst,
       .setDiscardResult()
       .setTailCall(IsTailCall);
 
-  std::pair<SDValue,SDValue> CallResult = TLI->LowerCallTo(CLI);
+  std::pair<SDValue, SDValue> CallResult = TLI->LowerCallTo(CLI);
   return CallResult.second;
 }
 
@@ -9716,8 +9790,9 @@ SDValue SelectionDAG::getMemset(SDValue Chain, const SDLoc &dl, SDValue Dst,
   // Then check to see if we should lower the memset with target-specific
   // code. If the target chooses to do this, this is the next best.
   if (TSI) {
-    SDValue Result = TSI->EmitTargetCodeForMemset(
-        *this, dl, Chain, Dst, Src, Size, Alignment, isVol, AlwaysInline, DstPtrInfo);
+    SDValue Result = TSI->EmitTargetCodeForMemset(*this, dl, Chain, Dst, Src,
+                                                  Size, Alignment, isVol,
+                                                  AlwaysInline, DstPtrInfo);
     if (Result.getNode())
       return Result;
   }
@@ -9738,7 +9813,7 @@ SDValue SelectionDAG::getMemset(SDValue Chain, const SDLoc &dl, SDValue Dst,
 
   // Emit a library call.
   auto &Ctx = *getContext();
-  const auto& DL = getDataLayout();
+  const auto &DL = getDataLayout();
 
   TargetLowering::CallLoweringInfo CLI(*this);
   // FIXME: pass in SDLoc
@@ -9827,7 +9902,7 @@ SDValue SelectionDAG::getAtomic(unsigned Opcode, const SDLoc &dl, EVT MemVT,
       dl.getIROrder(), Opcode, VTList, MemVT, MMO, ExtType));
   ID.AddInteger(MMO->getPointerInfo().getAddrSpace());
   ID.AddInteger(MMO->getFlags());
-  void* IP = nullptr;
+  void *IP = nullptr;
   if (auto *E = cast_or_null<AtomicSDNode>(FindNodeOrInsertPos(ID, dl, IP))) {
     E->refineAlignment(MMO);
     E->refineRanges(MMO);
@@ -9879,8 +9954,8 @@ SDValue SelectionDAG::getAtomic(unsigned Opcode, const SDLoc &dl, EVT MemVT,
 
   EVT VT = Val.getValueType();
 
-  SDVTList VTs = Opcode == ISD::ATOMIC_STORE ? getVTList(MVT::Other) :
-                                               getVTList(VT, MVT::Other);
+  SDVTList VTs = Opcode == ISD::ATOMIC_STORE ? getVTList(MVT::Other)
+                                             : getVTList(VT, MVT::Other);
   SDValue Ops[] = {Chain, Ptr, Val};
   return getAtomic(Opcode, dl, MemVT, VTs, Ops, MMO);
 }
@@ -9957,7 +10032,7 @@ SDValue SelectionDAG::getMemIntrinsicNode(unsigned Opcode, const SDLoc &dl,
 
   // Memoize the node unless it returns a glue result.
   MemIntrinsicSDNode *N;
-  if (VTList.VTs[VTList.NumVTs-1] != MVT::Glue) {
+  if (VTList.VTs[VTList.NumVTs - 1] != MVT::Glue) {
     FoldingSetNodeID ID;
     AddNodeIDNode(ID, Opcode, VTList, Ops);
     ID.AddInteger(getSyntheticNodeSubclassData<MemIntrinsicSDNode>(
@@ -10052,8 +10127,7 @@ static MachinePointerInfo InferPointerInfo(const MachinePointerInfo &Info,
                                              FI->getIndex(), Offset);
 
   // If this is (FI+Offset1)+Offset2, we can model it.
-  if (Ptr.getOpcode() != ISD::ADD ||
-      !isa<ConstantSDNode>(Ptr.getOperand(1)) ||
+  if (Ptr.getOpcode() != ISD::ADD || !isa<ConstantSDNode>(Ptr.getOperand(1)) ||
       !isa<FrameIndexSDNode>(Ptr.getOperand(0)))
     return Info;
 
@@ -10085,8 +10159,7 @@ SDValue SelectionDAG::getLoad(ISD::MemIndexedMode AM, ISD::LoadExtType ExtType,
                               Align Alignment,
                               MachineMemOperand::Flags MMOFlags,
                               const AAMDNodes &AAInfo, const MDNode *Ranges) {
-  assert(Chain.getValueType() == MVT::Other &&
-        "Invalid chain type");
+  assert(Chain.getValueType() == MVT::Other && "Invalid chain type");
 
   MMOFlags |= MachineMemOperand::MOLoad;
   assert((MMOFlags & MachineMemOperand::MOStore) == 0);
@@ -10132,9 +10205,9 @@ SDValue SelectionDAG::getLoad(ISD::MemIndexedMode AM, ISD::LoadExtType ExtType,
   bool Indexed = AM != ISD::UNINDEXED;
   assert((Indexed || Offset.isUndef()) && "Unindexed load with an offset!");
 
-  SDVTList VTs = Indexed ?
-    getVTList(VT, Ptr.getValueType(), MVT::Other) : getVTList(VT, MVT::Other);
-  SDValue Ops[] = { Chain, Ptr, Offset };
+  SDVTList VTs = Indexed ? getVTList(VT, Ptr.getValueType(), MVT::Other)
+                         : getVTList(VT, MVT::Other);
+  SDValue Ops[] = {Chain, Ptr, Offset};
   FoldingSetNodeID ID;
   AddNodeIDNode(ID, ISD::LOAD, VTs, Ops);
   ID.AddInteger(MemVT.getRawBits());
@@ -10191,8 +10264,8 @@ SDValue SelectionDAG::getExtLoad(ISD::LoadExtType ExtType, const SDLoc &dl,
                                  EVT VT, SDValue Chain, SDValue Ptr, EVT MemVT,
                                  MachineMemOperand *MMO) {
   SDValue Undef = getUNDEF(Ptr.getValueType());
-  return getLoad(ISD::UNINDEXED, ExtType, VT, dl, Chain, Ptr, Undef,
-                 MemVT, MMO);
+  return getLoad(ISD::UNINDEXED, ExtType, VT, dl, Chain, Ptr, Undef, MemVT,
+                 MMO);
 }
 
 SDValue SelectionDAG::getIndexedLoad(SDValue OrigLoad, const SDLoc &dl,
@@ -10290,8 +10363,7 @@ SDValue SelectionDAG::getTruncStore(SDValue Chain, const SDLoc &dl, SDValue Val,
                                     EVT SVT, Align Alignment,
                                     MachineMemOperand::Flags MMOFlags,
                                     const AAMDNodes &AAInfo) {
-  assert(Chain.getValueType() == MVT::Other &&
-        "Invalid chain type");
+  assert(Chain.getValueType() == MVT::Other && "Invalid chain type");
 
   MMOFlags |= MachineMemOperand::MOStore;
   assert((MMOFlags & MachineMemOperand::MOLoad) == 0);
@@ -10859,8 +10931,7 @@ SDValue SelectionDAG::getMaskedStore(SDValue Chain, const SDLoc &dl,
                                      MachineMemOperand *MMO,
                                      ISD::MemIndexedMode AM, bool IsTruncating,
                                      bool IsCompressing) {
-  assert(Chain.getValueType() == MVT::Other &&
-        "Invalid chain type");
+  assert(Chain.getValueType() == MVT::Other && "Invalid chain type");
   bool Indexed = AM != ISD::UNINDEXED;
   assert((Indexed || Offset.isUndef()) &&
          "Unindexed masked store with an offset!");
@@ -11173,8 +11244,8 @@ SDValue SelectionDAG::simplifyFPBinop(unsigned Opcode, SDValue X, SDValue Y,
   // operation is poison. That result can be relaxed to undef.
   ConstantFPSDNode *XC = isConstOrConstSplatFP(X, /* AllowUndefs */ true);
   ConstantFPSDNode *YC = isConstOrConstSplatFP(Y, /* AllowUndefs */ true);
-  bool HasNan = (XC && XC->getValueAPF().isNaN()) ||
-                (YC && YC->getValueAPF().isNaN());
+  bool HasNan =
+      (XC && XC->getValueAPF().isNaN()) || (YC && YC->getValueAPF().isNaN());
   bool HasInf = (XC && XC->getValueAPF().isInfinity()) ||
                 (YC && YC->getValueAPF().isInfinity());
 
@@ -11213,18 +11284,23 @@ SDValue SelectionDAG::simplifyFPBinop(unsigned Opcode, SDValue X, SDValue Y,
 
 SDValue SelectionDAG::getVAArg(EVT VT, const SDLoc &dl, SDValue Chain,
                                SDValue Ptr, SDValue SV, unsigned Align) {
-  SDValue Ops[] = { Chain, Ptr, SV, getTargetConstant(Align, dl, MVT::i32) };
+  SDValue Ops[] = {Chain, Ptr, SV, getTargetConstant(Align, dl, MVT::i32)};
   return getNode(ISD::VAARG, dl, getVTList(VT, MVT::Other), Ops);
 }
 
 SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
                               ArrayRef<SDUse> Ops) {
   switch (Ops.size()) {
-  case 0: return getNode(Opcode, DL, VT);
-  case 1: return getNode(Opcode, DL, VT, Ops[0].get());
-  case 2: return getNode(Opcode, DL, VT, Ops[0], Ops[1]);
-  case 3: return getNode(Opcode, DL, VT, Ops[0], Ops[1], Ops[2]);
-  default: break;
+  case 0:
+    return getNode(Opcode, DL, VT);
+  case 1:
+    return getNode(Opcode, DL, VT, Ops[0].get());
+  case 2:
+    return getNode(Opcode, DL, VT, Ops[0], Ops[1]);
+  case 3:
+    return getNode(Opcode, DL, VT, Ops[0], Ops[1], Ops[2]);
+  default:
+    break;
   }
 
   // Copy from an SDUse array into an SDValue array for use with
@@ -11245,21 +11321,26 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
                               ArrayRef<SDValue> Ops, const SDNodeFlags Flags) {
   unsigned NumOps = Ops.size();
   switch (NumOps) {
-  case 0: return getNode(Opcode, DL, VT);
-  case 1: return getNode(Opcode, DL, VT, Ops[0], Flags);
-  case 2: return getNode(Opcode, DL, VT, Ops[0], Ops[1], Flags);
-  case 3: return getNode(Opcode, DL, VT, Ops[0], Ops[1], Ops[2], Flags);
-  default: break;
+  case 0:
+    return getNode(Opcode, DL, VT);
+  case 1:
+    return getNode(Opcode, DL, VT, Ops[0], Flags);
+  case 2:
+    return getNode(Opcode, DL, VT, Ops[0], Ops[1], Flags);
+  case 3:
+    return getNode(Opcode, DL, VT, Ops[0], Ops[1], Ops[2], Flags);
+  default:
+    break;
   }
 
 #ifndef NDEBUG
   for (const auto &Op : Ops)
-    assert(Op.getOpcode() != ISD::DELETED_NODE &&
-           "Operand is DELETED_NODE!");
+    assert(Op.getOpcode() != ISD::DELETED_NODE && "Operand is DELETED_NODE!");
 #endif
 
   switch (Opcode) {
-  default: break;
+  default:
+    break;
   case ISD::BUILD_VECTOR:
     // Attempt to simplify BUILD_VECTOR.
     if (SDValue V = FoldBUILD_VECTOR(DL, VT, Ops, *this))
@@ -11384,8 +11465,7 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList,
 
 #ifndef NDEBUG
   for (const auto &Op : Ops)
-    assert(Op.getOpcode() != ISD::DELETED_NODE &&
-           "Operand is DELETED_NODE!");
+    assert(Op.getOpcode() != ISD::DELETED_NODE && "Operand is DELETED_NODE!");
 #endif
 
   switch (Opcode) {
@@ -11526,7 +11606,7 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList,
 
   // Memoize the node unless it returns a glue result.
   SDNode *N;
-  if (VTList.VTs[VTList.NumVTs-1] != MVT::Glue) {
+  if (VTList.VTs[VTList.NumVTs - 1] != MVT::Glue) {
     FoldingSetNodeID ID;
     AddNodeIDNode(ID, Opcode, VTList, Ops);
     void *IP = nullptr;
@@ -11557,32 +11637,32 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL,
 
 SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList,
                               SDValue N1) {
-  SDValue Ops[] = { N1 };
+  SDValue Ops[] = {N1};
   return getNode(Opcode, DL, VTList, Ops);
 }
 
 SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList,
                               SDValue N1, SDValue N2) {
-  SDValue Ops[] = { N1, N2 };
+  SDValue Ops[] = {N1, N2};
   return getNode(Opcode, DL, VTList, Ops);
 }
 
 SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList,
                               SDValue N1, SDValue N2, SDValue N3) {
-  SDValue Ops[] = { N1, N2, N3 };
+  SDValue Ops[] = {N1, N2, N3};
   return getNode(Opcode, DL, VTList, Ops);
 }
 
 SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList,
                               SDValue N1, SDValue N2, SDValue N3, SDValue N4) {
-  SDValue Ops[] = { N1, N2, N3, N4 };
+  SDValue Ops[] = {N1, N2, N3, N4};
   return getNode(Opcode, DL, VTList, Ops);
 }
 
 SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList,
                               SDValue N1, SDValue N2, SDValue N3, SDValue N4,
                               SDValue N5) {
-  SDValue Ops[] = { N1, N2, N3, N4, N5 };
+  SDValue Ops[] = {N1, N2, N3, N4, N5};
   return getNode(Opcode, DL, VTList, Ops);
 }
 
@@ -11672,7 +11752,6 @@ SDVTList SelectionDAG::getVTList(ArrayRef<EVT> VTs) {
   return Result->getSDVTList();
 }
 
-
 /// UpdateNodeOperands - *Mutate* the specified node in-place to have the
 /// specified operands.  If the resultant node already exists in the DAG,
 /// this does not modify the specified node, instead it returns the node that
@@ -11683,7 +11762,8 @@ SDNode *SelectionDAG::UpdateNodeOperands(SDNode *N, SDValue Op) {
   assert(N->getNumOperands() == 1 && "Update with wrong number of operands");
 
   // Check to see if there is no change.
-  if (Op == N->getOperand(0)) return N;
+  if (Op == N->getOperand(0))
+    return N;
 
   // See if the modified node already exists.
   void *InsertPos = nullptr;
@@ -11700,7 +11780,8 @@ SDNode *SelectionDAG::UpdateNodeOperands(SDNode *N, SDValue Op) {
 
   updateDivergence(N);
   // If this gets put into a CSE map, add it.
-  if (InsertPos) CSEMap.InsertNode(N, InsertPos);
+  if (InsertPos)
+    CSEMap.InsertNode(N, InsertPos);
   return N;
 }
 
@@ -11709,7 +11790,7 @@ SDNode *SelectionDAG::UpdateNodeOperands(SDNode *N, SDValue Op1, SDValue Op2) {
 
   // Check to see if there is no change.
   if (Op1 == N->getOperand(0) && Op2 == N->getOperand(1))
-    return N;   // No operands changed, just return the input node.
+    return N; // No operands changed, just return the input node.
 
   // See if the modified node already exists.
   void *InsertPos = nullptr;
@@ -11729,32 +11810,31 @@ SDNode *SelectionDAG::UpdateNodeOperands(SDNode *N, SDValue Op1, SDValue Op2) {
 
   updateDivergence(N);
   // If this gets put into a CSE map, add it.
-  if (InsertPos) CSEMap.InsertNode(N, InsertPos);
+  if (InsertPos)
+    CSEMap.InsertNode(N, InsertPos);
   return N;
 }
 
-SDNode *SelectionDAG::
-UpdateNodeOperands(SDNode *N, SDValue Op1, SDValue Op2, SDValue Op3) {
-  SDValue Ops[] = { Op1, Op2, Op3 };
+SDNode *SelectionDAG::UpdateNodeOperands(SDNode *N, SDValue Op1, SDValue Op2,
+                                         SDValue Op3) {
+  SDValue Ops[] = {Op1, Op2, Op3};
   return UpdateNodeOperands(N, Ops);
 }
 
-SDNode *SelectionDAG::
-UpdateNodeOperands(SDNode *N, SDValue Op1, SDValue Op2,
-                   SDValue Op3, SDValue Op4) {
-  SDValue Ops[] = { Op1, Op2, Op3, Op4 };
+SDNode *SelectionDAG::UpdateNodeOperands(SDNode *N, SDValue Op1, SDValue Op2,
+                                         SDValue Op3, SDValue Op4) {
+  SDValue Ops[] = {Op1, Op2, Op3, Op4};
   return UpdateNodeOperands(N, Ops);
 }
 
-SDNode *SelectionDAG::
-UpdateNodeOperands(SDNode *N, SDValue Op1, SDValue Op2,
-                   SDValue Op3, SDValue Op4, SDValue Op5) {
-  SDValue Ops[] = { Op1, Op2, Op3, Op4, Op5 };
+SDNode *SelectionDAG::UpdateNodeOperands(SDNode *N, SDValue Op1, SDValue Op2,
+                                         SDValue Op3, SDValue Op4,
+                                         SDValue Op5) {
+  SDValue Ops[] = {Op1, Op2, Op3, Op4, Op5};
   return UpdateNodeOperands(N, Ops);
 }
 
-SDNode *SelectionDAG::
-UpdateNodeOperands(SDNode *N, ArrayRef<SDValue> Ops) {
+SDNode *SelectionDAG::UpdateNodeOperands(SDNode *N, ArrayRef<SDValue> Ops) {
   unsigned NumOps = Ops.size();
   assert(N->getNumOperands() == NumOps &&
          "Update with wrong number of operands");
@@ -11780,7 +11860,8 @@ UpdateNodeOperands(SDNode *N, ArrayRef<SDValue> Ops) {
 
   updateDivergence(N);
   // If this gets put into a CSE map, add it.
-  if (InsertPos) CSEMap.InsertNode(N, InsertPos);
+  if (InsertPos)
+    CSEMap.InsertNode(N, InsertPos);
   return N;
 }
 
@@ -11789,7 +11870,7 @@ UpdateNodeOperands(SDNode *N, ArrayRef<SDValue> Ops) {
 void SDNode::DropOperands() {
   // Unlike the code in MorphNodeTo that does this, we don't need to
   // watch for dead nodes here.
-  for (op_iterator I = op_begin(), E = op_end(); I != E; ) {
+  for (op_iterator I = op_begin(), E = op_end(); I != E;) {
     SDUse &Use = *I++;
     Use.set(SDValue());
   }
@@ -11819,70 +11900,65 @@ void SelectionDAG::setNodeMemRefs(MachineSDNode *N,
 /// SelectNodeTo - These are wrappers around MorphNodeTo that accept a
 /// machine opcode.
 ///
-SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc,
-                                   EVT VT) {
+SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT) {
   SDVTList VTs = getVTList(VT);
   return SelectNodeTo(N, MachineOpc, VTs, {});
 }
 
-SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc,
-                                   EVT VT, SDValue Op1) {
+SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT,
+                                   SDValue Op1) {
   SDVTList VTs = getVTList(VT);
-  SDValue Ops[] = { Op1 };
+  SDValue Ops[] = {Op1};
   return SelectNodeTo(N, MachineOpc, VTs, Ops);
 }
 
-SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc,
-                                   EVT VT, SDValue Op1,
-                                   SDValue Op2) {
+SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT,
+                                   SDValue Op1, SDValue Op2) {
   SDVTList VTs = getVTList(VT);
-  SDValue Ops[] = { Op1, Op2 };
+  SDValue Ops[] = {Op1, Op2};
   return SelectNodeTo(N, MachineOpc, VTs, Ops);
 }
 
-SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc,
-                                   EVT VT, SDValue Op1,
-                                   SDValue Op2, SDValue Op3) {
+SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT,
+                                   SDValue Op1, SDValue Op2, SDValue Op3) {
   SDVTList VTs = getVTList(VT);
-  SDValue Ops[] = { Op1, Op2, Op3 };
+  SDValue Ops[] = {Op1, Op2, Op3};
   return SelectNodeTo(N, MachineOpc, VTs, Ops);
 }
 
-SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc,
-                                   EVT VT, ArrayRef<SDValue> Ops) {
+SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT,
+                                   ArrayRef<SDValue> Ops) {
   SDVTList VTs = getVTList(VT);
   return SelectNodeTo(N, MachineOpc, VTs, Ops);
 }
 
-SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc,
-                                   EVT VT1, EVT VT2, ArrayRef<SDValue> Ops) {
+SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT1,
+                                   EVT VT2, ArrayRef<SDValue> Ops) {
   SDVTList VTs = getVTList(VT1, VT2);
   return SelectNodeTo(N, MachineOpc, VTs, Ops);
 }
 
-SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc,
-                                   EVT VT1, EVT VT2) {
+SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT1,
+                                   EVT VT2) {
   SDVTList VTs = getVTList(VT1, VT2);
   return SelectNodeTo(N, MachineOpc, VTs, {});
 }
 
-SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc,
-                                   EVT VT1, EVT VT2, EVT VT3,
-                                   ArrayRef<SDValue> Ops) {
+SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT1,
+                                   EVT VT2, EVT VT3, ArrayRef<SDValue> Ops) {
   SDVTList VTs = getVTList(VT1, VT2, VT3);
   return SelectNodeTo(N, MachineOpc, VTs, Ops);
 }
 
-SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc,
-                                   EVT VT1, EVT VT2,
-                                   SDValue Op1, SDValue Op2) {
+SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT1,
+                                   EVT VT2, SDValue Op1, SDValue Op2) {
   SDVTList VTs = getVTList(VT1, VT2);
-  SDValue Ops[] = { Op1, Op2 };
+  SDValue Ops[] = {Op1, Op2};
   return SelectNodeTo(N, MachineOpc, VTs, Ops);
 }
 
-SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc,
-                                   SDVTList VTs,ArrayRef<SDValue> Ops) {
+SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc, SDVTList VTs,
+                                   ArrayRef<SDValue> Ops) {
   SDNode *New = MorphNodeTo(N, ~MachineOpc, VTs, Ops);
   // Reset the NodeID to -1.
   New->setNodeId(-1);
@@ -11926,11 +12002,11 @@ SDNode *SelectionDAG::UpdateSDLocOnMergeSDNode(SDNode *N, const SDLoc &OLoc) {
 /// As a consequence it isn't appropriate to use from within the DAG combiner or
 /// the legalizer which maintain worklists that would need to be updated when
 /// deleting things.
-SDNode *SelectionDAG::MorphNodeTo(SDNode *N, unsigned Opc,
-                                  SDVTList VTs, ArrayRef<SDValue> Ops) {
+SDNode *SelectionDAG::MorphNodeTo(SDNode *N, unsigned Opc, SDVTList VTs,
+                                  ArrayRef<SDValue> Ops) {
   // If an identical node already exists, use it.
   void *IP = nullptr;
-  if (VTs.VTs[VTs.NumVTs-1] != MVT::Glue) {
+  if (VTs.VTs[VTs.NumVTs - 1] != MVT::Glue) {
     FoldingSetNodeID ID;
     AddNodeIDNode(ID, Opc, VTs, Ops);
     if (SDNode *ON = FindNodeOrInsertPos(ID, SDLoc(N), IP))
@@ -11947,8 +12023,8 @@ SDNode *SelectionDAG::MorphNodeTo(SDNode *N, unsigned Opc,
 
   // Clear the operands list, updating used nodes to remove this from their
   // use list.  Keep track of any operands that become dead as a result.
-  SmallPtrSet<SDNode*, 16> DeadNodeSet;
-  for (SDNode::op_iterator I = N->op_begin(), E = N->op_end(); I != E; ) {
+  SmallPtrSet<SDNode *, 16> DeadNodeSet;
+  for (SDNode::op_iterator I = N->op_begin(), E = N->op_end(); I != E;) {
     SDUse &Use = *I++;
     SDNode *Used = Use.getNode();
     Use.set(SDValue());
@@ -11975,20 +12051,24 @@ SDNode *SelectionDAG::MorphNodeTo(SDNode *N, unsigned Opc,
   }
 
   if (IP)
-    CSEMap.InsertNode(N, IP);   // Memoize the new node.
+    CSEMap.InsertNode(N, IP); // Memoize the new node.
   return N;
 }
 
-SDNode* SelectionDAG::mutateStrictFPToFP(SDNode *Node) {
+SDNode *SelectionDAG::mutateStrictFPToFP(SDNode *Node) {
   unsigned OrigOpc = Node->getOpcode();
   unsigned NewOpc;
   switch (OrigOpc) {
   default:
     llvm_unreachable("mutateStrictFPToFP called with unexpected opcode!");
 #define DAG_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN)               \
-  case ISD::STRICT_##DAGN: NewOpc = ISD::DAGN; break;
+  case ISD::STRICT_##DAGN:                                                     \
+    NewOpc = ISD::DAGN;                                                        \
+    break;
 #define CMP_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN)               \
-  case ISD::STRICT_##DAGN: NewOpc = ISD::SETCC; break;
+  case ISD::STRICT_##DAGN:                                                     \
+    NewOpc = ISD::SETCC;                                                       \
+    break;
 #include "llvm/IR/ConstrainedOps.def"
   }
 
@@ -12036,14 +12116,14 @@ MachineSDNode *SelectionDAG::getMachineNode(unsigned Opcode, const SDLoc &dl,
 MachineSDNode *SelectionDAG::getMachineNode(unsigned Opcode, const SDLoc &dl,
                                             EVT VT, SDValue Op1) {
   SDVTList VTs = getVTList(VT);
-  SDValue Ops[] = { Op1 };
+  SDValue Ops[] = {Op1};
   return getMachineNode(Opcode, dl, VTs, Ops);
 }
 
 MachineSDNode *SelectionDAG::getMachineNode(unsigned Opcode, const SDLoc &dl,
                                             EVT VT, SDValue Op1, SDValue Op2) {
   SDVTList VTs = getVTList(VT);
-  SDValue Ops[] = { Op1, Op2 };
+  SDValue Ops[] = {Op1, Op2};
   return getMachineNode(Opcode, dl, VTs, Ops);
 }
 
@@ -12051,7 +12131,7 @@ MachineSDNode *SelectionDAG::getMachineNode(unsigned Opcode, const SDLoc &dl,
                                             EVT VT, SDValue Op1, SDValue Op2,
                                             SDValue Op3) {
   SDVTList VTs = getVTList(VT);
-  SDValue Ops[] = { Op1, Op2, Op3 };
+  SDValue Ops[] = {Op1, Op2, Op3};
   return getMachineNode(Opcode, dl, VTs, Ops);
 }
 
@@ -12065,7 +12145,7 @@ MachineSDNode *SelectionDAG::getMachineNode(unsigned Opcode, const SDLoc &dl,
                                             EVT VT1, EVT VT2, SDValue Op1,
                                             SDValue Op2) {
   SDVTList VTs = getVTList(VT1, VT2);
-  SDValue Ops[] = { Op1, Op2 };
+  SDValue Ops[] = {Op1, Op2};
   return getMachineNode(Opcode, dl, VTs, Ops);
 }
 
@@ -12073,7 +12153,7 @@ MachineSDNode *SelectionDAG::getMachineNode(unsigned Opcode, const SDLoc &dl,
                                             EVT VT1, EVT VT2, SDValue Op1,
                                             SDValue Op2, SDValue Op3) {
   SDVTList VTs = getVTList(VT1, VT2);
-  SDValue Ops[] = { Op1, Op2, Op3 };
+  SDValue Ops[] = {Op1, Op2, Op3};
   return getMachineNode(Opcode, dl, VTs, Ops);
 }
 
@@ -12088,7 +12168,7 @@ MachineSDNode *SelectionDAG::getMachineNode(unsigned Opcode, const SDLoc &dl,
                                             EVT VT1, EVT VT2, EVT VT3,
                                             SDValue Op1, SDValue Op2) {
   SDVTList VTs = getVTList(VT1, VT2, VT3);
-  SDValue Ops[] = { Op1, Op2 };
+  SDValue Ops[] = {Op1, Op2};
   return getMachineNode(Opcode, dl, VTs, Ops);
 }
 
@@ -12097,7 +12177,7 @@ MachineSDNode *SelectionDAG::getMachineNode(unsigned Opcode, const SDLoc &dl,
                                             SDValue Op1, SDValue Op2,
                                             SDValue Op3) {
   SDVTList VTs = getVTList(VT1, VT2, VT3);
-  SDValue Ops[] = { Op1, Op2, Op3 };
+  SDValue Ops[] = {Op1, Op2, Op3};
   return getMachineNode(Opcode, dl, VTs, Ops);
 }
 
@@ -12118,7 +12198,7 @@ MachineSDNode *SelectionDAG::getMachineNode(unsigned Opcode, const SDLoc &dl,
 MachineSDNode *SelectionDAG::getMachineNode(unsigned Opcode, const SDLoc &DL,
                                             SDVTList VTs,
                                             ArrayRef<SDValue> Ops) {
-  bool DoCSE = VTs.VTs[VTs.NumVTs-1] != MVT::Glue;
+  bool DoCSE = VTs.VTs[VTs.NumVTs - 1] != MVT::Glue;
   MachineSDNode *N;
   void *IP = nullptr;
 
@@ -12148,8 +12228,8 @@ MachineSDNode *SelectionDAG::getMachineNode(unsigned Opcode, const SDLoc &DL,
 SDValue SelectionDAG::getTargetExtractSubreg(int SRIdx, const SDLoc &DL, EVT VT,
                                              SDValue Operand) {
   SDValue SRIdxVal = getTargetConstant(SRIdx, DL, MVT::i32);
-  SDNode *Subreg = getMachineNode(TargetOpcode::EXTRACT_SUBREG, DL,
-                                  VT, Operand, SRIdxVal);
+  SDNode *Subreg =
+      getMachineNode(TargetOpcode::EXTRACT_SUBREG, DL, VT, Operand, SRIdxVal);
   return SDValue(Subreg, 0);
 }
 
@@ -12158,8 +12238,8 @@ SDValue SelectionDAG::getTargetExtractSubreg(int SRIdx, const SDLoc &DL, EVT VT,
 SDValue SelectionDAG::getTargetInsertSubreg(int SRIdx, const SDLoc &DL, EVT VT,
                                             SDValue Operand, SDValue Subreg) {
   SDValue SRIdxVal = getTargetConstant(SRIdx, DL, MVT::i32);
-  SDNode *Result = getMachineNode(TargetOpcode::INSERT_SUBREG, DL,
-                                  VT, Operand, Subreg, SRIdxVal);
+  SDNode *Result = getMachineNode(TargetOpcode::INSERT_SUBREG, DL, VT, Operand,
+                                  Subreg, SRIdxVal);
   return SDValue(Result, 0);
 }
 
@@ -12507,8 +12587,8 @@ void SelectionDAG::salvageDebugInfo(SDNode &N) {
 }
 
 /// Creates a SDDbgLabel node.
-SDDbgLabel *SelectionDAG::getDbgLabel(DILabel *Label,
-                                      const DebugLoc &DL, unsigned O) {
+SDDbgLabel *SelectionDAG::getDbgLabel(DILabel *Label, const DebugLoc &DL,
+                                      unsigned O) {
   assert(cast<DILabel>(Label)->isValidLocationForIntrinsic(DL) &&
          "Expected inlined-at fields to agree");
   return new (DbgInfo->getAlloc()) SDDbgLabel(Label, DL, O);
@@ -12531,10 +12611,9 @@ class RAUWUpdateListener : public SelectionDAG::DAGUpdateListener {
   }
 
 public:
-  RAUWUpdateListener(SelectionDAG &d,
-                     SDNode::use_iterator &ui,
+  RAUWUpdateListener(SelectionDAG &d, SDNode::use_iterator &ui,
                      SDNode::use_iterator &ue)
-    : SelectionDAG::DAGUpdateListener(d), UI(ui), UE(ue) {}
+      : SelectionDAG::DAGUpdateListener(d), UI(ui), UE(ue) {}
 };
 
 } // end anonymous namespace
@@ -12656,7 +12735,7 @@ void SelectionDAG::ReplaceAllUsesWith(SDNode *From, SDNode *To) {
 /// This version can replace From with any result values.  To must match the
 /// number and types of values returned by From.
 void SelectionDAG::ReplaceAllUsesWith(SDNode *From, const SDValue *To) {
-  if (From->getNumValues() == 1)  // Handle the simple case efficiently.
+  if (From->getNumValues() == 1) // Handle the simple case efficiently.
     return ReplaceAllUsesWith(SDValue(From, 0), To[0]);
 
   for (unsigned i = 0, e = From->getNumValues(); i != e; ++i) {
@@ -12706,9 +12785,10 @@ void SelectionDAG::ReplaceAllUsesWith(SDNode *From, const SDValue *To) {
 /// ReplaceAllUsesOfValueWith - Replace any uses of From with To, leaving
 /// uses of other values produced by From.getNode() alone.  The Deleted
 /// vector is handled the same way as for ReplaceAllUsesWith.
-void SelectionDAG::ReplaceAllUsesOfValueWith(SDValue From, SDValue To){
+void SelectionDAG::ReplaceAllUsesOfValueWith(SDValue From, SDValue To) {
   // Handle the really simple, really trivial case efficiently.
-  if (From == To) return;
+  if (From == To)
+    return;
 
   // Handle the simple, trivial, case efficiently.
   if (From.getNode()->getNumValues() == 1) {
@@ -12882,8 +12962,7 @@ void SelectionDAG::VerifyDAGDivergence() {
 /// may appear in both the From and To list.  The Deleted vector is
 /// handled the same way as for ReplaceAllUsesWith.
 void SelectionDAG::ReplaceAllUsesOfValuesWith(const SDValue *From,
-                                              const SDValue *To,
-                                              unsigned Num){
+                                              const SDValue *To, unsigned Num) {
   // Handle the simple, trivial case efficiently.
   if (Num == 1)
     return ReplaceAllUsesOfValueWith(*From, *To);
@@ -12911,7 +12990,7 @@ void SelectionDAG::ReplaceAllUsesOfValuesWith(const SDValue *From,
   RAUOVWUpdateListener Listener(*this, Uses);
 
   for (unsigned UseIndex = 0, UseIndexEnd = Uses.size();
-       UseIndex != UseIndexEnd; ) {
+       UseIndex != UseIndexEnd;) {
     // We know that this user uses some value of From.  If it is the right
     // value, update it.
     SDNode *User = Uses[UseIndex].User;
@@ -13006,7 +13085,8 @@ unsigned SelectionDAG::AssignTopologicalOrder() {
       allnodes_iterator I(N);
       SDNode *S = &*++I;
       dbgs() << "Overran sorted position:\n";
-      S->dumprFull(this); dbgs() << "\n";
+      S->dumprFull(this);
+      dbgs() << "\n";
       dbgs() << "Checking if this is due to cycles\n";
       checkForCycles(this, true);
 #endif
@@ -13014,15 +13094,14 @@ unsigned SelectionDAG::AssignTopologicalOrder() {
     }
   }
 
-  assert(SortedPos == AllNodes.end() &&
-         "Topological sort incomplete!");
+  assert(SortedPos == AllNodes.end() && "Topological sort incomplete!");
   assert(AllNodes.front().getOpcode() == ISD::EntryToken &&
          "First node in topological sort is not the entry token!");
   assert(AllNodes.front().getNodeId() == 0 &&
          "First node in topological sort has non-zero id!");
   assert(AllNodes.front().getNumOperands() == 0 &&
          "First node in topological sort has operands!");
-  assert(AllNodes.back().getNodeId() == (int)DAGSize-1 &&
+  assert(AllNodes.back().getNodeId() == (int)DAGSize - 1 &&
          "Last node in topologic sort has unexpected id!");
   assert(AllNodes.back().use_empty() &&
          "Last node in topologic sort has users!");
@@ -13120,10 +13199,11 @@ SDValue SelectionDAG::getSymbolFunctionGlobalAddress(SDValue Op,
   auto *Function = Module->getFunction(Symbol);
 
   if (OutFunction != nullptr)
-      *OutFunction = Function;
+    *OutFunction = Function;
 
   if (Function != nullptr) {
-    auto PtrTy = TLI->getPointerTy(getDataLayout(), Function->getAddressSpace());
+    auto PtrTy =
+        TLI->getPointerTy(getDataLayout(), Function->getAddressSpace());
     return getGlobalAddress(Function, SDLoc(Op), PtrTy);
   }
 
@@ -13215,11 +13295,9 @@ bool llvm::isNeutralConstant(unsigned Opcode, SDNodeFlags Flags, SDValue V,
       // Neutral element for fminnum is NaN, Inf or FLT_MAX, depending on FMF.
       EVT VT = V.getValueType();
       const fltSemantics &Semantics = VT.getFltSemantics();
-      APFloat NeutralAF = !Flags.hasNoNaNs()
-                              ? APFloat::getQNaN(Semantics)
-                              : !Flags.hasNoInfs()
-                                    ? APFloat::getInf(Semantics)
-                                    : APFloat::getLargest(Semantics);
+      APFloat NeutralAF = !Flags.hasNoNaNs()   ? APFloat::getQNaN(Semantics)
+                          : !Flags.hasNoInfs() ? APFloat::getInf(Semantics)
+                                               : APFloat::getLargest(Semantics);
       if (Opcode == ISD::FMAXNUM)
         NeutralAF.changeSign();
 
@@ -13399,9 +13477,7 @@ bool llvm::isZeroOrZeroSplatFP(SDValue N, bool AllowUndefs) {
   return C && C->isZero();
 }
 
-HandleSDNode::~HandleSDNode() {
-  DropOperands();
-}
+HandleSDNode::~HandleSDNode() { DropOperands(); }
 
 MemSDNode::MemSDNode(
     unsigned Opc, unsigned Order, const DebugLoc &dl, SDVTList VTs, EVT memvt,
@@ -13434,21 +13510,19 @@ MemSDNode::MemSDNode(
 
 /// Profile - Gather unique data for the node.
 ///
-void SDNode::Profile(FoldingSetNodeID &ID) const {
-  AddNodeIDNode(ID, this);
-}
+void SDNode::Profile(FoldingSetNodeID &ID) const { AddNodeIDNode(ID, this); }
 
 namespace {
 
-  struct EVTArray {
-    std::vector<EVT> VTs;
+struct EVTArray {
+  std::vector<EVT> VTs;
 
-    EVTArray() {
-      VTs.reserve(MVT::VALUETYPE_SIZE);
-      for (unsigned i = 0; i < MVT::VALUETYPE_SIZE; ++i)
-        VTs.push_back(MVT((MVT::SimpleValueType)i));
-    }
-  };
+  EVTArray() {
+    VTs.reserve(MVT::VALUETYPE_SIZE);
+    for (unsigned i = 0; i < MVT::VALUETYPE_SIZE; ++i)
+      VTs.push_back(MVT((MVT::SimpleValueType)i));
+  }
+};
 
 } // end anonymous namespace
 
@@ -13521,11 +13595,13 @@ bool SDNode::isOperandOf(const SDNode *N) const {
 /// constraint is necessary to allow transformations like splitting loads.
 bool SDValue::reachesChainWithoutSideEffects(SDValue Dest,
                                              unsigned Depth) const {
-  if (*this == Dest) return true;
+  if (*this == Dest)
+    return true;
 
   // Don't search too deeply, we just want to be able to see through
   // TokenFactor's etc.
-  if (Depth == 0) return false;
+  if (Depth == 0)
+    return false;
 
   // If this is a token factor, all inputs to the TF happen in parallel.
   if (getOpcode() == ISD::TokenFactor) {
@@ -13552,7 +13628,7 @@ bool SDValue::reachesChainWithoutSideEffects(SDValue Dest,
   // Loads don't have side effects, look through them.
   if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(*this)) {
     if (Ld->isUnordered())
-      return Ld->getChain().reachesChainWithoutSideEffects(Dest, Depth-1);
+      return Ld->getChain().reachesChainWithoutSideEffects(Dest, Depth - 1);
   }
   return false;
 }
@@ -13738,7 +13814,7 @@ SDValue SelectionDAG::UnrollVectorOp(SDNode *N, unsigned ResNE) {
   SmallVector<SDValue, 4> Operands(N->getNumOperands());
 
   unsigned i;
-  for (i= 0; i != NE; ++i) {
+  for (i = 0; i != NE; ++i) {
     for (unsigned j = 0, e = N->getNumOperands(); j != e; ++j) {
       SDValue Operand = N->getOperand(j);
       EVT OperandVT = Operand.getValueType();
@@ -13754,8 +13830,8 @@ SDValue SelectionDAG::UnrollVectorOp(SDNode *N, unsigned ResNE) {
 
     switch (N->getOpcode()) {
     default: {
-      Scalars.push_back(getNode(N->getOpcode(), dl, EltVT, Operands,
-                                N->getFlags()));
+      Scalars.push_back(
+          getNode(N->getOpcode(), dl, EltVT, Operands, N->getFlags()));
       break;
     }
     case ISD::VSELECT:
@@ -13766,15 +13842,14 @@ SDValue SelectionDAG::UnrollVectorOp(SDNode *N, unsigned ResNE) {
     case ISD::SRL:
     case ISD::ROTL:
     case ISD::ROTR:
-      Scalars.push_back(getNode(N->getOpcode(), dl, EltVT, Operands[0],
-                               getShiftAmountOperand(Operands[0].getValueType(),
-                                                     Operands[1])));
+      Scalars.push_back(getNode(
+          N->getOpcode(), dl, EltVT, Operands[0],
+          getShiftAmountOperand(Operands[0].getValueType(), Operands[1])));
       break;
     case ISD::SIGN_EXTEND_INREG: {
       EVT ExtVT = cast<VTSDNode>(Operands[1])->getVT().getVectorElementType();
-      Scalars.push_back(getNode(N->getOpcode(), dl, EltVT,
-                                Operands[0],
-                                getValueType(ExtVT)));
+      Scalars.push_back(
+          getNode(N->getOpcode(), dl, EltVT, Operands[0], getValueType(ExtVT)));
       break;
     }
     case ISD::ADDRSPACECAST: {
@@ -13794,8 +13869,8 @@ SDValue SelectionDAG::UnrollVectorOp(SDNode *N, unsigned ResNE) {
   return getBuildVector(VecVT, dl, Scalars);
 }
 
-std::pair<SDValue, SDValue> SelectionDAG::UnrollVectorOverflowOp(
-    SDNode *N, unsigned ResNE) {
+std::pair<SDValue, SDValue>
+SelectionDAG::UnrollVectorOverflowOp(SDNode *N, unsigned ResNE) {
   unsigned Opcode = N->getOpcode();
   assert((Opcode == ISD::UADDO || Opcode == ISD::SADDO ||
           Opcode == ISD::USUBO || Opcode == ISD::SSUBO ||
@@ -13826,10 +13901,9 @@ std::pair<SDValue, SDValue> SelectionDAG::UnrollVectorOverflowOp(
   SmallVector<SDValue, 8> OvScalars;
   for (unsigned i = 0; i < NE; ++i) {
     SDValue Res = getNode(Opcode, dl, VTs, LHSScalars[i], RHSScalars[i]);
-    SDValue Ov =
-        getSelect(dl, OvEltVT, Res.getValue(1),
-                  getBoolConstant(true, dl, OvEltVT, ResVT),
-                  getConstant(0, dl, OvEltVT));
+    SDValue Ov = getSelect(dl, OvEltVT, Res.getValue(1),
+                           getBoolConstant(true, dl, OvEltVT, ResVT),
+                           getConstant(0, dl, OvEltVT));
 
     ResScalars.push_back(Res);
     OvScalars.push_back(Ov);
@@ -13967,9 +14041,10 @@ SelectionDAG::GetDependentSplitDestVTs(const EVT &VT, const EVT &EnvVT,
 
 /// SplitVector - Split the vector with EXTRACT_SUBVECTOR and return the
 /// low/high part.
-std::pair<SDValue, SDValue>
-SelectionDAG::SplitVector(const SDValue &N, const SDLoc &DL, const EVT &LoVT,
-                          const EVT &HiVT) {
+std::pair<SDValue, SDValue> SelectionDAG::SplitVector(const SDValue &N,
+                                                      const SDLoc &DL,
+                                                      const EVT &LoVT,
+                                                      const EVT &HiVT) {
   assert(LoVT.isScalableVector() == HiVT.isScalableVector() &&
          LoVT.isScalableVector() == N.getValueType().isScalableVector() &&
          "Splitting vector with an invalid mixture of fixed and scalable "
@@ -14292,8 +14367,7 @@ void BuildVectorSDNode::recastRawBits(bool IsLittleEndian,
   unsigned SrcEltSizeInBits = SrcBitElements[0].getBitWidth();
   assert(((NumSrcOps * SrcEltSizeInBits) % DstEltSizeInBits) == 0 &&
          "Invalid bitcast scale");
-  assert(NumSrcOps == SrcUndefElements.size() &&
-         "Vector size mismatch");
+  assert(NumSrcOps == SrcUndefElements.size() && "Vector size mismatch");
 
   unsigned NumDstOps = (NumSrcOps * SrcEltSizeInBits) / DstEltSizeInBits;
   DstUndefElements.clear();
@@ -14441,8 +14515,7 @@ bool SelectionDAG::isConstantIntBuildVectorOrConstantInt(
   // Treat a GlobalAddress supporting constant offset folding as a
   // constant integer.
   if (auto *GA = dyn_cast<GlobalAddressSDNode>(N))
-    if (GA->getOpcode() == ISD::GlobalAddress &&
-        TLI->isOffsetFoldingLegal(GA))
+    if (GA->getOpcode() == ISD::GlobalAddress && TLI->isOffsetFoldingLegal(GA))
       return true;
 
   if ((N.getOpcode() == ISD::SPLAT_VECTOR) &&
@@ -14564,9 +14637,9 @@ SDValue SelectionDAG::getNeutralElement(unsigned Opcode, const SDLoc &DL,
   case ISD::FMAXNUM: {
     // Neutral element for fminnum is NaN, Inf or FLT_MAX, depending on FMF.
     const fltSemantics &Semantics = VT.getFltSemantics();
-    APFloat NeutralAF = !Flags.hasNoNaNs() ? APFloat::getQNaN(Semantics) :
-                        !Flags.hasNoInfs() ? APFloat::getInf(Semantics) :
-                        APFloat::getLargest(Semantics);
+    APFloat NeutralAF = !Flags.hasNoNaNs()   ? APFloat::getQNaN(Semantics)
+                        : !Flags.hasNoInfs() ? APFloat::getInf(Semantics)
+                                             : APFloat::getLargest(Semantics);
     if (Opcode == ISD::FMAXNUM)
       NeutralAF.changeSign();
 
@@ -14583,7 +14656,6 @@ SDValue SelectionDAG::getNeutralElement(unsigned Opcode, const SDLoc &DL,
 
     return getConstantFP(NeutralAF, DL, VT);
   }
-
   }
 }
 
@@ -14723,8 +14795,8 @@ void SelectionDAG::copyExtraInfo(SDNode *From, SDNode *To) {
 
 #ifndef NDEBUG
 static void checkForCyclesHelper(const SDNode *N,
-                                 SmallPtrSetImpl<const SDNode*> &Visited,
-                                 SmallPtrSetImpl<const SDNode*> &Checked,
+                                 SmallPtrSetImpl<const SDNode *> &Visited,
+                                 SmallPtrSetImpl<const SDNode *> &Checked,
                                  const llvm::SelectionDAG *DAG) {
   // If this node has already been checked, don't check it again.
   if (Checked.count(N))
@@ -14735,7 +14807,8 @@ static void checkForCyclesHelper(const SDNode *N,
   if (!Visited.insert(N).second) {
     errs() << "Detected cycle in SelectionDAG\n";
     dbgs() << "Offending node:\n";
-    N->dumprFull(DAG); dbgs() << "\n";
+    N->dumprFull(DAG);
+    dbgs() << "\n";
     abort();
   }
 
@@ -14747,21 +14820,20 @@ static void checkForCyclesHelper(const SDNode *N,
 }
 #endif
 
-void llvm::checkForCycles(const llvm::SDNode *N,
-                          const llvm::SelectionDAG *DAG,
+void llvm::checkForCycles(const llvm::SDNode *N, const llvm::SelectionDAG *DAG,
                           bool force) {
 #ifndef NDEBUG
   bool check = force;
 #ifdef EXPENSIVE_CHECKS
   check = true;
-#endif  // EXPENSIVE_CHECKS
+#endif // EXPENSIVE_CHECKS
   if (check) {
     assert(N && "Checking nonexistent SDNode");
-    SmallPtrSet<const SDNode*, 32> visited;
-    SmallPtrSet<const SDNode*, 32> checked;
+    SmallPtrSet<const SDNode *, 32> visited;
+    SmallPtrSet<const SDNode *, 32> checked;
     checkForCyclesHelper(N, visited, checked, DAG);
   }
-#endif  // !NDEBUG
+#endif // !NDEBUG
 }
 
 void llvm::checkForCycles(const llvm::SelectionDAG *DAG, bool force) {
diff --git a/llvm/unittests/Target/AArch64/AArch64SelectionDAGTest.cpp b/llvm/unittests/Target/AArch64/AArch64SelectionDAGTest.cpp
index 9833ee3fdbc51..09e604808db83 100644
--- a/llvm/unittests/Target/AArch64/AArch64SelectionDAGTest.cpp
+++ b/llvm/unittests/Target/AArch64/AArch64SelectionDAGTest.cpp
@@ -1579,15 +1579,22 @@ TEST_F(AArch64SelectionDAGTest, KnownNeverZero_Div) {
   SDLoc Loc;
   auto Cst0 = DAG->getConstant(0, Loc, MVT::i32);
   auto Cst1 = DAG->getConstant(1, Loc, MVT::i32);
+  auto Cst2 = DAG->getConstant(2, Loc, MVT::i32);
+
   auto Cst4 = DAG->getConstant(4, Loc, MVT::i32);
   auto Neg1 = DAG->getNode(ISD::SUB, Loc, MVT::i32, Cst0, Cst1);
   auto Neg4 = DAG->getNode(ISD::SUB, Loc, MVT::i32, Cst0, Cst4);
 
-  auto UDiv04 = DAG->getNode(ISD::UDIV, Loc, MVT::i32, Cst0, Cst4);
-  auto UDiv41 = DAG->getNode(ISD::UDIV, Loc, MVT::i32, Cst4, Cst1);
-  auto UDivNeg41 = DAG->getNode(ISD::UDIV, Loc, MVT::i32, Neg4, Cst1);
-  auto UDiv4Neg1 = DAG->getNode(ISD::UDIV, Loc, MVT::i32, Cst4, Neg1);
-  auto UDivNeg1Neg4 = DAG->getNode(ISD::UDIV, Loc, MVT::i32, Neg1, Neg4);
+  auto UDiv04 =
+      DAG->getNode(ISD::UDIV, Loc, MVT::i32, Cst0, Cst4, SDNodeFlags::Exact);
+  auto UDiv41 =
+      DAG->getNode(ISD::UDIV, Loc, MVT::i32, Cst4, Cst1, SDNodeFlags::Exact);
+  auto UDivNeg41 =
+      DAG->getNode(ISD::UDIV, Loc, MVT::i32, Neg4, Cst1, SDNodeFlags::Exact);
+  auto UDiv4Neg1 =
+      DAG->getNode(ISD::UDIV, Loc, MVT::i32, Cst4, Neg1, SDNodeFlags::Exact);
+  auto UDivNeg1Neg4 =
+      DAG->getNode(ISD::UDIV, Loc, MVT::i32, Neg1, Neg4, SDNodeFlags::Exact);
 
   EXPECT_FALSE(DAG->isKnownNeverZero(UDiv04));
   EXPECT_TRUE(DAG->isKnownNeverZero(UDiv41));
@@ -1595,16 +1602,69 @@ TEST_F(AArch64SelectionDAGTest, KnownNeverZero_Div) {
   EXPECT_FALSE(DAG->isKnownNeverZero(UDiv4Neg1));
   EXPECT_TRUE(DAG->isKnownNeverZero(UDivNeg1Neg4));
 
-  auto SDiv04 = DAG->getNode(ISD::SDIV, Loc, MVT::i32, Cst0, Cst4);
-  auto SDiv41 = DAG->getNode(ISD::SDIV, Loc, MVT::i32, Cst4, Cst1);
-  auto SDivNeg41 = DAG->getNode(ISD::SDIV, Loc, MVT::i32, Neg4, Cst1);
-  auto SDiv4Neg1 = DAG->getNode(ISD::SDIV, Loc, MVT::i32, Cst4, Neg1);
-  auto SDivNeg1Neg4 = DAG->getNode(ISD::SDIV, Loc, MVT::i32, Neg1, Neg4);
+  auto SDiv04 =
+      DAG->getNode(ISD::SDIV, Loc, MVT::i32, Cst0, Cst4, SDNodeFlags::Exact);
+  auto SDiv41 =
+      DAG->getNode(ISD::SDIV, Loc, MVT::i32, Cst4, Cst1, SDNodeFlags::Exact);
+  auto SDivNeg41 =
+      DAG->getNode(ISD::SDIV, Loc, MVT::i32, Neg4, Cst1, SDNodeFlags::Exact);
+  auto SDiv4Neg1 =
+      DAG->getNode(ISD::SDIV, Loc, MVT::i32, Cst4, Neg1, SDNodeFlags::Exact);
+  auto SDivNeg1Neg4 =
+      DAG->getNode(ISD::SDIV, Loc, MVT::i32, Neg1, Neg4, SDNodeFlags::Exact);
 
   EXPECT_FALSE(DAG->isKnownNeverZero(SDiv04));
   EXPECT_TRUE(DAG->isKnownNeverZero(SDiv41));
   EXPECT_TRUE(DAG->isKnownNeverZero(SDivNeg41));
   EXPECT_TRUE(DAG->isKnownNeverZero(SDiv4Neg1));
   EXPECT_FALSE(DAG->isKnownNeverZero(SDivNeg1Neg4));
+
+  auto VecVT = MVT::v2i16;
+  auto Vec00 = DAG->getBuildVector(VecVT, Loc, {Cst0, Cst0});
+  auto Vec40 = DAG->getBuildVector(VecVT, Loc, {Cst4, Cst0});
+  auto Vec14 = DAG->getBuildVector(VecVT, Loc, {Cst1, Cst4});
+  auto Vec42 = DAG->getBuildVector(VecVT, Loc, {Cst4, Cst2});
+  auto Vec44 = DAG->getBuildVector(VecVT, Loc, {Cst4, Cst4});
+  auto VecNeg1Neg4 = DAG->getBuildVector(VecVT, Loc, {Neg1, Neg4});
+
+  APInt DemandLo(2, 1);
+  APInt DemandHi(2, 2);
+  APInt DemandAll(2, 3);
+
+  auto VUDiv4044 =
+      DAG->getNode(ISD::UDIV, Loc, VecVT, Vec40, Vec44, SDNodeFlags::Exact);
+  auto VUDiv1442 =
+      DAG->getNode(ISD::UDIV, Loc, VecVT, Vec14, Vec42, SDNodeFlags::Exact);
+  auto VUDiv4414 =
+      DAG->getNode(ISD::UDIV, Loc, VecVT, Vec44, Vec14, SDNodeFlags::Exact);
+  auto VUDiv14Neg1Neg4 = DAG->getNode(ISD::UDIV, Loc, VecVT, Vec14, VecNeg1Neg4,
+                                      SDNodeFlags::Exact);
+
+  EXPECT_TRUE(DAG->isKnownNeverZero(VUDiv4044, DemandLo));
+  EXPECT_FALSE(DAG->isKnownNeverZero(VUDiv1442, DemandLo));
+
+  EXPECT_FALSE(DAG->isKnownNeverZero(VUDiv4044, DemandHi));
+  EXPECT_TRUE(DAG->isKnownNeverZero(VUDiv1442, DemandHi));
+
+  EXPECT_FALSE(DAG->isKnownNeverZero(VUDiv14Neg1Neg4, DemandAll));
+  EXPECT_TRUE(DAG->isKnownNeverZero(VUDiv4414, DemandAll));
+
+  auto VSDiv0044 =
+      DAG->getNode(ISD::SDIV, Loc, VecVT, Vec00, Vec44, SDNodeFlags::Exact);
+  auto VSDiv4044 =
+      DAG->getNode(ISD::SDIV, Loc, VecVT, Vec40, Vec44, SDNodeFlags::Exact);
+  auto VSDiv1442 =
+      DAG->getNode(ISD::SDIV, Loc, VecVT, Vec14, Vec42, SDNodeFlags::Exact);
+  auto VSDiv14Neg1Neg4 = DAG->getNode(ISD::SDIV, Loc, VecVT, Vec14, VecNeg1Neg4,
+                                      SDNodeFlags::Exact);
+
+  EXPECT_TRUE(DAG->isKnownNeverZero(VSDiv4044, DemandLo));
+  EXPECT_FALSE(DAG->isKnownNeverZero(VSDiv1442, DemandLo));
+
+  EXPECT_FALSE(DAG->isKnownNeverZero(VSDiv4044, DemandHi));
+  EXPECT_TRUE(DAG->isKnownNeverZero(VSDiv1442, DemandHi));
+
+  EXPECT_TRUE(DAG->isKnownNeverZero(VSDiv14Neg1Neg4, DemandAll));
+  EXPECT_FALSE(DAG->isKnownNeverZero(VSDiv0044, DemandAll));
 }
 } // end namespace llvm

>From 687951fec015bee1a17bc016d4c88bf0bdf16c3a Mon Sep 17 00:00:00 2001
From: Ayokunle Amodu <ayokunle321 at gmail.com>
Date: Tue, 24 Feb 2026 19:41:36 -0700
Subject: [PATCH 4/7] undo format for selectionDag source

---
 .../lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 1056 ++++++++---------
 1 file changed, 492 insertions(+), 564 deletions(-)

diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 0b5fbd06293c4..6311671e1b474 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -91,8 +91,8 @@ static SDVTList makeVTList(const EVT *VTs, unsigned NumVTs) {
 }
 
 // Default null implementations of the callbacks.
-void SelectionDAG::DAGUpdateListener::NodeDeleted(SDNode *, SDNode *) {}
-void SelectionDAG::DAGUpdateListener::NodeUpdated(SDNode *) {}
+void SelectionDAG::DAGUpdateListener::NodeDeleted(SDNode*, SDNode*) {}
+void SelectionDAG::DAGUpdateListener::NodeUpdated(SDNode*) {}
 void SelectionDAG::DAGUpdateListener::NodeInserted(SDNode *) {}
 
 void SelectionDAG::DAGNodeDeletedListener::anchor() {}
@@ -100,14 +100,13 @@ void SelectionDAG::DAGNodeInsertedListener::anchor() {}
 
 #define DEBUG_TYPE "selectiondag"
 
-static cl::opt<bool> EnableMemCpyDAGOpt(
-    "enable-memcpy-dag-opt", cl::Hidden, cl::init(true),
-    cl::desc("Gang up loads and stores generated by inlining of memcpy"));
+static cl::opt<bool> EnableMemCpyDAGOpt("enable-memcpy-dag-opt",
+       cl::Hidden, cl::init(true),
+       cl::desc("Gang up loads and stores generated by inlining of memcpy"));
 
-static cl::opt<int>
-    MaxLdStGlue("ldstmemcpy-glue-max",
-                cl::desc("Number limit for gluing ld/st of memcpy."),
-                cl::Hidden, cl::init(0));
+static cl::opt<int> MaxLdStGlue("ldstmemcpy-glue-max",
+       cl::desc("Number limit for gluing ld/st of memcpy."),
+       cl::Hidden, cl::init(0));
 
 static cl::opt<unsigned>
     MaxSteps("has-predecessor-max-steps", cl::Hidden, cl::init(8192),
@@ -128,11 +127,12 @@ unsigned SelectionDAG::getHasPredecessorMaxSteps() { return MaxSteps; }
 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
 /// As such, this method can be used to do an exact bit-for-bit comparison of
 /// two floating point values.
-bool ConstantFPSDNode::isExactlyValue(const APFloat &V) const {
+bool ConstantFPSDNode::isExactlyValue(const APFloat& V) const {
   return getValueAPF().bitwiseIsEqual(V);
 }
 
-bool ConstantFPSDNode::isValueValidForType(EVT VT, const APFloat &Val) {
+bool ConstantFPSDNode::isValueValidForType(EVT VT,
+                                           const APFloat& Val) {
   assert(VT.isFloatingPoint() && "Can only convert between FP types");
 
   // convert modifies in place, so make a copy.
@@ -188,8 +188,7 @@ bool ISD::isConstantSplatVectorAllOnes(const SDNode *N, bool BuildVectorOnly) {
     return isConstantSplatVector(N, SplatVal) && SplatVal.isAllOnes();
   }
 
-  if (N->getOpcode() != ISD::BUILD_VECTOR)
-    return false;
+  if (N->getOpcode() != ISD::BUILD_VECTOR) return false;
 
   unsigned i = 0, e = N->getNumOperands();
 
@@ -198,8 +197,7 @@ bool ISD::isConstantSplatVectorAllOnes(const SDNode *N, bool BuildVectorOnly) {
     ++i;
 
   // Do not accept an all-undef vector.
-  if (i == e)
-    return false;
+  if (i == e) return false;
 
   // Do not accept build_vectors that aren't all constants or which have non-~0
   // elements. We have to be a bit careful here, as the type of the constant
@@ -236,8 +234,7 @@ bool ISD::isConstantSplatVectorAllZeros(const SDNode *N, bool BuildVectorOnly) {
     return isConstantSplatVector(N, SplatVal) && SplatVal.isZero();
   }
 
-  if (N->getOpcode() != ISD::BUILD_VECTOR)
-    return false;
+  if (N->getOpcode() != ISD::BUILD_VECTOR) return false;
 
   bool IsAllUndef = true;
   for (const SDValue &Op : N->op_values()) {
@@ -624,20 +621,20 @@ ISD::CondCode ISD::getSetCCSwappedOperands(ISD::CondCode Operation) {
   // operation.
   unsigned OldL = (Operation >> 2) & 1;
   unsigned OldG = (Operation >> 1) & 1;
-  return ISD::CondCode((Operation & ~6) | // Keep the N, U, E bits
-                       (OldL << 1) |      // New G bit
-                       (OldG << 2));      // New L bit.
+  return ISD::CondCode((Operation & ~6) |  // Keep the N, U, E bits
+                       (OldL << 1) |       // New G bit
+                       (OldG << 2));       // New L bit.
 }
 
 static ISD::CondCode getSetCCInverseImpl(ISD::CondCode Op, bool isIntegerLike) {
   unsigned Operation = Op;
   if (isIntegerLike)
-    Operation ^= 7; // Flip L, G, E bits, but not U.
+    Operation ^= 7;   // Flip L, G, E bits, but not U.
   else
-    Operation ^= 15; // Flip all of the condition bits.
+    Operation ^= 15;  // Flip all of the condition bits.
 
   if (Operation > ISD::SETTRUE2)
-    Operation &= ~8; // Don't let N and U bits get set.
+    Operation &= ~8;  // Don't let N and U bits get set.
 
   return ISD::CondCode(Operation);
 }
@@ -656,21 +653,17 @@ ISD::CondCode ISD::GlobalISel::getSetCCInverse(ISD::CondCode Op,
 /// does not depend on the sign of the input (setne and seteq).
 static int isSignedOp(ISD::CondCode Opcode) {
   switch (Opcode) {
-  default:
-    llvm_unreachable("Illegal integer setcc operation!");
+  default: llvm_unreachable("Illegal integer setcc operation!");
   case ISD::SETEQ:
-  case ISD::SETNE:
-    return 0;
+  case ISD::SETNE: return 0;
   case ISD::SETLT:
   case ISD::SETLE:
   case ISD::SETGT:
-  case ISD::SETGE:
-    return 1;
+  case ISD::SETGE: return 1;
   case ISD::SETULT:
   case ISD::SETULE:
   case ISD::SETUGT:
-  case ISD::SETUGE:
-    return 2;
+  case ISD::SETUGE: return 2;
   }
 }
 
@@ -681,15 +674,15 @@ ISD::CondCode ISD::getSetCCOrOperation(ISD::CondCode Op1, ISD::CondCode Op2,
     // Cannot fold a signed integer setcc with an unsigned integer setcc.
     return ISD::SETCC_INVALID;
 
-  unsigned Op = Op1 | Op2; // Combine all of the condition bits.
+  unsigned Op = Op1 | Op2;  // Combine all of the condition bits.
 
   // If the N and U bits get set, then the resultant comparison DOES suddenly
   // care about orderedness, and it is true when ordered.
   if (Op > ISD::SETTRUE2)
-    Op &= ~16; // Clear the U bit if the N bit is set.
+    Op &= ~16;     // Clear the U bit if the N bit is set.
 
   // Canonicalize illegal integer setcc's.
-  if (IsInteger && Op == ISD::SETUNE) // e.g. SETUGT | SETULT
+  if (IsInteger && Op == ISD::SETUNE)  // e.g. SETUGT | SETULT
     Op = ISD::SETNE;
 
   return ISD::CondCode(Op);
@@ -708,21 +701,12 @@ ISD::CondCode ISD::getSetCCAndOperation(ISD::CondCode Op1, ISD::CondCode Op2,
   // Canonicalize illegal integer setcc's.
   if (IsInteger) {
     switch (Result) {
-    default:
-      break;
-    case ISD::SETUO:
-      Result = ISD::SETFALSE;
-      break;          // SETUGT & SETULT
-    case ISD::SETOEQ: // SETEQ  & SETU[LG]E
-    case ISD::SETUEQ:
-      Result = ISD::SETEQ;
-      break; // SETUGE & SETULE
-    case ISD::SETOLT:
-      Result = ISD::SETULT;
-      break; // SETULT & SETNE
-    case ISD::SETOGT:
-      Result = ISD::SETUGT;
-      break; // SETUGT & SETNE
+    default: break;
+    case ISD::SETUO : Result = ISD::SETFALSE; break;  // SETUGT & SETULT
+    case ISD::SETOEQ:                                 // SETEQ  & SETU[LG]E
+    case ISD::SETUEQ: Result = ISD::SETEQ   ; break;  // SETUGE & SETULE
+    case ISD::SETOLT: Result = ISD::SETULT  ; break;  // SETULT & SETNE
+    case ISD::SETOGT: Result = ISD::SETUGT  ; break;  // SETUGT & SETNE
     }
   }
 
@@ -734,7 +718,7 @@ ISD::CondCode ISD::getSetCCAndOperation(ISD::CondCode Op1, ISD::CondCode Op2,
 //===----------------------------------------------------------------------===//
 
 /// AddNodeIDOpcode - Add the node opcode to the NodeID data.
-static void AddNodeIDOpcode(FoldingSetNodeID &ID, unsigned OpC) {
+static void AddNodeIDOpcode(FoldingSetNodeID &ID, unsigned OpC)  {
   ID.AddInteger(OpC);
 }
 
@@ -745,7 +729,8 @@ static void AddNodeIDValueTypes(FoldingSetNodeID &ID, SDVTList VTList) {
 }
 
 /// AddNodeIDOperands - Various routines for adding operands to the NodeID data.
-static void AddNodeIDOperands(FoldingSetNodeID &ID, ArrayRef<SDValue> Ops) {
+static void AddNodeIDOperands(FoldingSetNodeID &ID,
+                              ArrayRef<SDValue> Ops) {
   for (const auto &Op : Ops) {
     ID.AddPointer(Op.getNode());
     ID.AddInteger(Op.getResNo());
@@ -753,15 +738,16 @@ static void AddNodeIDOperands(FoldingSetNodeID &ID, ArrayRef<SDValue> Ops) {
 }
 
 /// AddNodeIDOperands - Various routines for adding operands to the NodeID data.
-static void AddNodeIDOperands(FoldingSetNodeID &ID, ArrayRef<SDUse> Ops) {
+static void AddNodeIDOperands(FoldingSetNodeID &ID,
+                              ArrayRef<SDUse> Ops) {
   for (const auto &Op : Ops) {
     ID.AddPointer(Op.getNode());
     ID.AddInteger(Op.getResNo());
   }
 }
 
-static void AddNodeIDNode(FoldingSetNodeID &ID, unsigned OpC, SDVTList VTList,
-                          ArrayRef<SDValue> OpList) {
+static void AddNodeIDNode(FoldingSetNodeID &ID, unsigned OpC,
+                          SDVTList VTList, ArrayRef<SDValue> OpList) {
   AddNodeIDOpcode(ID, OpC);
   AddNodeIDValueTypes(ID, VTList);
   AddNodeIDOperands(ID, OpList);
@@ -774,8 +760,7 @@ static void AddNodeIDCustom(FoldingSetNodeID &ID, const SDNode *N) {
   case ISD::ExternalSymbol:
   case ISD::MCSymbol:
     llvm_unreachable("Should only be used on nodes with operands");
-  default:
-    break; // Normal nodes don't need extra info.
+  default: break;  // Normal nodes don't need extra info.
   case ISD::TargetConstant:
   case ISD::Constant: {
     const ConstantSDNode *C = cast<ConstantSDNode>(N);
@@ -1035,11 +1020,10 @@ static bool doNotCSE(SDNode *N) {
     return true; // Never CSE anything that produces a glue result.
 
   switch (N->getOpcode()) {
-  default:
-    break;
+  default: break;
   case ISD::HANDLENODE:
   case ISD::EH_LABEL:
-    return true; // Never CSE these nodes.
+    return true;   // Never CSE these nodes.
   }
 
   // Check that remaining values produced are not flags.
@@ -1057,7 +1041,7 @@ void SelectionDAG::RemoveDeadNodes() {
   // to the root node, preventing it from being deleted.
   HandleSDNode Dummy(getRoot());
 
-  SmallVector<SDNode *, 128> DeadNodes;
+  SmallVector<SDNode*, 128> DeadNodes;
 
   // Add all obviously-dead nodes to the DeadNodes worklist.
   for (SDNode &Node : allnodes())
@@ -1092,7 +1076,7 @@ void SelectionDAG::RemoveDeadNodes(SmallVectorImpl<SDNode *> &DeadNodes) {
 
     // Next, brutally remove the operand list.  This is safe to do, as there are
     // no cycles in the graph.
-    for (SDNode::op_iterator I = N->op_begin(), E = N->op_end(); I != E;) {
+    for (SDNode::op_iterator I = N->op_begin(), E = N->op_end(); I != E; ) {
       SDUse &Use = *I++;
       SDNode *Operand = Use.getNode();
       Use.set(SDValue());
@@ -1106,8 +1090,8 @@ void SelectionDAG::RemoveDeadNodes(SmallVectorImpl<SDNode *> &DeadNodes) {
   }
 }
 
-void SelectionDAG::RemoveDeadNode(SDNode *N) {
-  SmallVector<SDNode *, 16> DeadNodes(1, N);
+void SelectionDAG::RemoveDeadNode(SDNode *N){
+  SmallVector<SDNode*, 16> DeadNodes(1, N);
 
   // Create a dummy node that adds a reference to the root node, preventing
   // it from being deleted.  (This matters if the root is an operand of the
@@ -1152,7 +1136,7 @@ void SDDbgInfo::erase(const SDNode *Node) {
   DbgValMapType::iterator I = DbgValMap.find(Node);
   if (I == DbgValMap.end())
     return;
-  for (auto &Val : I->second)
+  for (auto &Val: I->second)
     Val->setIsInvalidated();
   DbgValMap.erase(I);
 }
@@ -1254,8 +1238,7 @@ void SelectionDAG::InsertNode(SDNode *N) {
 bool SelectionDAG::RemoveNodeFromCSEMaps(SDNode *N) {
   bool Erased = false;
   switch (N->getOpcode()) {
-  case ISD::HANDLENODE:
-    return false; // noop.
+  case ISD::HANDLENODE: return false;  // noop.
   case ISD::CONDCODE:
     assert(CondCodeNodes[cast<CondCodeSDNode>(N)->get()] &&
            "Cond code doesn't exist!");
@@ -1297,7 +1280,7 @@ bool SelectionDAG::RemoveNodeFromCSEMaps(SDNode *N) {
   // Verify that the node was actually in one of the CSE maps, unless it has a
   // glue result (which cannot be CSE'd) or is one of the special cases that are
   // not subject to CSE.
-  if (!Erased && N->getValueType(N->getNumValues() - 1) != MVT::Glue &&
+  if (!Erased && N->getValueType(N->getNumValues()-1) != MVT::Glue &&
       !N->isMachineOpcode() && !doNotCSE(N)) {
     N->dump(this);
     dbgs() << "\n";
@@ -1311,7 +1294,8 @@ bool SelectionDAG::RemoveNodeFromCSEMaps(SDNode *N) {
 /// maps and modified in place. Add it back to the CSE maps, unless an identical
 /// node already exists, in which case transfer all its users to the existing
 /// node. This transfer can potentially trigger recursive merging.
-void SelectionDAG::AddModifiedNodeToCSEMaps(SDNode *N) {
+void
+SelectionDAG::AddModifiedNodeToCSEMaps(SDNode *N) {
   // For node types that aren't CSE'd, just act as if no identical node
   // already exists.
   if (!doNotCSE(N)) {
@@ -1347,7 +1331,7 @@ SDNode *SelectionDAG::FindModifiedNodeSlot(SDNode *N, SDValue Op,
   if (doNotCSE(N))
     return nullptr;
 
-  SDValue Ops[] = {Op};
+  SDValue Ops[] = { Op };
   FoldingSetNodeID ID;
   AddNodeIDNode(ID, N->getOpcode(), N->getVTList(), Ops);
   AddNodeIDCustom(ID, N);
@@ -1361,12 +1345,13 @@ SDNode *SelectionDAG::FindModifiedNodeSlot(SDNode *N, SDValue Op,
 /// were replaced with those specified.  If this node is never memoized,
 /// return null, otherwise return a pointer to the slot it would take.  If a
 /// node already exists with these operands, the slot will be non-null.
-SDNode *SelectionDAG::FindModifiedNodeSlot(SDNode *N, SDValue Op1, SDValue Op2,
+SDNode *SelectionDAG::FindModifiedNodeSlot(SDNode *N,
+                                           SDValue Op1, SDValue Op2,
                                            void *&InsertPos) {
   if (doNotCSE(N))
     return nullptr;
 
-  SDValue Ops[] = {Op1, Op2};
+  SDValue Ops[] = { Op1, Op2 };
   FoldingSetNodeID ID;
   AddNodeIDNode(ID, N->getOpcode(), N->getVTList(), Ops);
   AddNodeIDCustom(ID, N);
@@ -1458,8 +1443,7 @@ SDNode *SelectionDAG::FindNodeOrInsertPos(const FoldingSetNodeID &ID,
   SDNode *N = CSEMap.FindNodeOrInsertPos(ID, InsertPos);
   if (N) {
     switch (N->getOpcode()) {
-    default:
-      break;
+    default: break;
     case ISD::Constant:
     case ISD::ConstantFP:
       llvm_unreachable("Querying for Constant and ConstantFP nodes requires "
@@ -1536,18 +1520,21 @@ SelectionDAG::getStrictFPExtendOrRound(SDValue Op, SDValue Chain,
 }
 
 SDValue SelectionDAG::getAnyExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT) {
-  return VT.bitsGT(Op.getValueType()) ? getNode(ISD::ANY_EXTEND, DL, VT, Op)
-                                      : getNode(ISD::TRUNCATE, DL, VT, Op);
+  return VT.bitsGT(Op.getValueType()) ?
+    getNode(ISD::ANY_EXTEND, DL, VT, Op) :
+    getNode(ISD::TRUNCATE, DL, VT, Op);
 }
 
 SDValue SelectionDAG::getSExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT) {
-  return VT.bitsGT(Op.getValueType()) ? getNode(ISD::SIGN_EXTEND, DL, VT, Op)
-                                      : getNode(ISD::TRUNCATE, DL, VT, Op);
+  return VT.bitsGT(Op.getValueType()) ?
+    getNode(ISD::SIGN_EXTEND, DL, VT, Op) :
+    getNode(ISD::TRUNCATE, DL, VT, Op);
 }
 
 SDValue SelectionDAG::getZExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT) {
-  return VT.bitsGT(Op.getValueType()) ? getNode(ISD::ZERO_EXTEND, DL, VT, Op)
-                                      : getNode(ISD::TRUNCATE, DL, VT, Op);
+  return VT.bitsGT(Op.getValueType()) ?
+    getNode(ISD::ZERO_EXTEND, DL, VT, Op) :
+    getNode(ISD::TRUNCATE, DL, VT, Op);
 }
 
 SDValue SelectionDAG::getBitcastedAnyExtOrTrunc(SDValue Op, const SDLoc &DL,
@@ -1566,7 +1553,7 @@ SDValue SelectionDAG::getBitcastedAnyExtOrTrunc(SDValue Op, const SDLoc &DL,
 }
 
 SDValue SelectionDAG::getBitcastedSExtOrTrunc(SDValue Op, const SDLoc &DL,
-                                              EVT VT) {
+                                               EVT VT) {
   assert(!VT.isVector());
   auto Type = Op.getValueType();
   SDValue DestOp;
@@ -1581,7 +1568,7 @@ SDValue SelectionDAG::getBitcastedSExtOrTrunc(SDValue Op, const SDLoc &DL,
 }
 
 SDValue SelectionDAG::getBitcastedZExtOrTrunc(SDValue Op, const SDLoc &DL,
-                                              EVT VT) {
+                                               EVT VT) {
   assert(!VT.isVector());
   auto Type = Op.getValueType();
   SDValue DestOp;
@@ -1759,7 +1746,8 @@ SDValue SelectionDAG::getConstant(const ConstantInt &Val, const SDLoc &DL,
     unsigned ViaEltSizeInBits = ViaEltVT.getSizeInBits();
 
     // For scalable vectors, try to use a SPLAT_VECTOR_PARTS node.
-    if (VT.isScalableVector() || TLI->isOperationLegal(ISD::SPLAT_VECTOR, VT)) {
+    if (VT.isScalableVector() ||
+        TLI->isOperationLegal(ISD::SPLAT_VECTOR, VT)) {
       assert(EltVT.getSizeInBits() % ViaEltSizeInBits == 0 &&
              "Can only handle an even split!");
       unsigned Parts = EltVT.getSizeInBits() / ViaEltSizeInBits;
@@ -1962,7 +1950,7 @@ SDValue SelectionDAG::getGlobalAddress(const GlobalValue *GV, const SDLoc &DL,
   auto *N = newSDNode<GlobalAddressSDNode>(
       Opc, DL.getIROrder(), DL.getDebugLoc(), GV, VTs, Offset, TargetFlags);
   CSEMap.InsertNode(N, IP);
-  InsertNode(N);
+    InsertNode(N);
   return SDValue(N, 0);
 }
 
@@ -2095,15 +2083,14 @@ SDValue SelectionDAG::getBasicBlock(MachineBasicBlock *MBB) {
 }
 
 SDValue SelectionDAG::getValueType(EVT VT) {
-  if (VT.isSimple() &&
-      (unsigned)VT.getSimpleVT().SimpleTy >= ValueTypeNodes.size())
-    ValueTypeNodes.resize(VT.getSimpleVT().SimpleTy + 1);
+  if (VT.isSimple() && (unsigned)VT.getSimpleVT().SimpleTy >=
+      ValueTypeNodes.size())
+    ValueTypeNodes.resize(VT.getSimpleVT().SimpleTy+1);
 
-  SDNode *&N = VT.isExtended() ? ExtendedValueTypeNodes[VT]
-                               : ValueTypeNodes[VT.getSimpleVT().SimpleTy];
+  SDNode *&N = VT.isExtended() ?
+    ExtendedValueTypeNodes[VT] : ValueTypeNodes[VT.getSimpleVT().SimpleTy];
 
-  if (N)
-    return SDValue(N, 0);
+  if (N) return SDValue(N, 0);
   N = newSDNode<VTSDNode>(VT);
   InsertNode(N);
   return SDValue(N, 0);
@@ -2111,8 +2098,7 @@ SDValue SelectionDAG::getValueType(EVT VT) {
 
 SDValue SelectionDAG::getExternalSymbol(const char *Sym, EVT VT) {
   SDNode *&N = ExternalSymbols[Sym];
-  if (N)
-    return SDValue(N, 0);
+  if (N) return SDValue(N, 0);
   N = newSDNode<ExternalSymbolSDNode>(false, Sym, 0, getVTList(VT));
   InsertNode(N);
   return SDValue(N, 0);
@@ -2136,8 +2122,7 @@ SDValue SelectionDAG::getTargetExternalSymbol(const char *Sym, EVT VT,
                                               unsigned TargetFlags) {
   SDNode *&N =
       TargetExternalSymbols[std::pair<std::string, unsigned>(Sym, TargetFlags)];
-  if (N)
-    return SDValue(N, 0);
+  if (N) return SDValue(N, 0);
   N = newSDNode<ExternalSymbolSDNode>(true, Sym, TargetFlags, getVTList(VT));
   InsertNode(N);
   return SDValue(N, 0);
@@ -2151,7 +2136,7 @@ SDValue SelectionDAG::getTargetExternalSymbol(RTLIB::LibcallImpl Libcall,
 
 SDValue SelectionDAG::getCondCode(ISD::CondCode Cond) {
   if ((unsigned)Cond >= CondCodeNodes.size())
-    CondCodeNodes.resize(Cond + 1);
+    CondCodeNodes.resize(Cond+1);
 
   if (!CondCodeNodes[Cond]) {
     auto *N = newSDNode<CondCodeSDNode>(Cond);
@@ -2250,9 +2235,9 @@ SDValue SelectionDAG::getVectorShuffle(EVT VT, const SDLoc &dl, SDValue N1,
   // Validate that all indices in Mask are within the range of the elements
   // input to the shuffle.
   int NElts = Mask.size();
-  assert(
-      llvm::all_of(Mask, [&](int M) { return M < (NElts * 2) && M >= -1; }) &&
-      "Index out of range");
+  assert(llvm::all_of(Mask,
+                      [&](int M) { return M < (NElts * 2) && M >= -1; }) &&
+         "Index out of range");
 
   // Copy the mask so we can do any needed cleanup.
   SmallVector<int, 8> MaskVec(Mask);
@@ -2261,8 +2246,7 @@ SDValue SelectionDAG::getVectorShuffle(EVT VT, const SDLoc &dl, SDValue N1,
   if (N1 == N2) {
     N2 = getUNDEF(VT);
     for (int i = 0; i != NElts; ++i)
-      if (MaskVec[i] >= NElts)
-        MaskVec[i] -= NElts;
+      if (MaskVec[i] >= NElts) MaskVec[i] -= NElts;
   }
 
   // Canonicalize shuffle undef, v -> v, undef.  Commute the shuffle mask.
@@ -2330,10 +2314,8 @@ SDValue SelectionDAG::getVectorShuffle(EVT VT, const SDLoc &dl, SDValue N1,
   // If Identity shuffle return that node.
   bool Identity = true, AllSame = true;
   for (int i = 0; i != NElts; ++i) {
-    if (MaskVec[i] >= 0 && MaskVec[i] != i)
-      Identity = false;
-    if (MaskVec[i] != MaskVec[0])
-      AllSame = false;
+    if (MaskVec[i] >= 0 && MaskVec[i] != i) Identity = false;
+    if (MaskVec[i] != MaskVec[0]) AllSame = false;
   }
   if (Identity && NElts)
     return N1;
@@ -2384,12 +2366,12 @@ SDValue SelectionDAG::getVectorShuffle(EVT VT, const SDLoc &dl, SDValue N1,
 
   SDVTList VTs = getVTList(VT);
   FoldingSetNodeID ID;
-  SDValue Ops[2] = {N1, N2};
+  SDValue Ops[2] = { N1, N2 };
   AddNodeIDNode(ID, ISD::VECTOR_SHUFFLE, VTs, Ops);
   for (int i = 0; i != NElts; ++i)
     ID.AddInteger(MaskVec[i]);
 
-  void *IP = nullptr;
+  void* IP = nullptr;
   if (SDNode *E = FindNodeOrInsertPos(ID, dl, IP))
     return SDValue(E, 0);
 
@@ -2458,7 +2440,7 @@ SDValue SelectionDAG::getEHLabel(const SDLoc &dl, SDValue Root,
 SDValue SelectionDAG::getLabelNode(unsigned Opcode, const SDLoc &dl,
                                    SDValue Root, MCSymbol *Label) {
   FoldingSetNodeID ID;
-  SDValue Ops[] = {Root};
+  SDValue Ops[] = { Root };
   AddNodeIDNode(ID, Opcode, getVTList(MVT::Other), Ops);
   ID.AddPointer(Label);
   void *IP = nullptr;
@@ -2570,8 +2552,7 @@ SDValue SelectionDAG::getFreeze(SDValue V, const APInt &DemandedElts,
 SDValue SelectionDAG::getShiftAmountOperand(EVT LHSTy, SDValue Op) {
   EVT OpTy = Op.getValueType();
   EVT ShTy = TLI->getShiftAmountTy(LHSTy, getDataLayout());
-  if (OpTy == ShTy || OpTy.isVector())
-    return Op;
+  if (OpTy == ShTy || OpTy.isVector()) return Op;
 
   return getZExtOrTrunc(Op, SDLoc(Op), ShTy);
 }
@@ -2601,7 +2582,7 @@ SDValue SelectionDAG::expandVAArg(SDNode *Node) {
   // Increment the pointer, VAList, to the next vaarg
   Tmp1 = getNode(ISD::ADD, dl, VAList.getValueType(), VAList,
                  getConstant(getDataLayout().getTypeAllocSize(
-                                 VT.getTypeForEVT(*getContext())),
+                                               VT.getTypeForEVT(*getContext())),
                              dl, VAList.getValueType()));
   // Store the incremented VAList to the legalized pointer
   Tmp1 =
@@ -2711,14 +2692,11 @@ SDValue SelectionDAG::FoldSetCC(EVT VT, SDValue N1, SDValue N2,
 
   // These setcc operations always fold.
   switch (Cond) {
-  default:
-    break;
+  default: break;
   case ISD::SETFALSE:
-  case ISD::SETFALSE2:
-    return getBoolConstant(false, dl, VT, OpVT);
+  case ISD::SETFALSE2: return getBoolConstant(false, dl, VT, OpVT);
   case ISD::SETTRUE:
-  case ISD::SETTRUE2:
-    return getBoolConstant(true, dl, VT, OpVT);
+  case ISD::SETTRUE2: return getBoolConstant(true, dl, VT, OpVT);
 
   case ISD::SETOEQ:
   case ISD::SETOGT:
@@ -2770,69 +2748,58 @@ SDValue SelectionDAG::FoldSetCC(EVT VT, SDValue N1, SDValue N2,
   if (N1CFP && N2CFP) {
     APFloat::cmpResult R = N1CFP->getValueAPF().compare(N2CFP->getValueAPF());
     switch (Cond) {
-    default:
-      break;
-    case ISD::SETEQ:
-      if (R == APFloat::cmpUnordered)
-        return GetUndefBooleanConstant();
-      [[fallthrough]];
-    case ISD::SETOEQ:
-      return getBoolConstant(R == APFloat::cmpEqual, dl, VT, OpVT);
-    case ISD::SETNE:
-      if (R == APFloat::cmpUnordered)
-        return GetUndefBooleanConstant();
-      [[fallthrough]];
-    case ISD::SETONE:
-      return getBoolConstant(R == APFloat::cmpGreaterThan ||
-                                 R == APFloat::cmpLessThan,
-                             dl, VT, OpVT);
-    case ISD::SETLT:
-      if (R == APFloat::cmpUnordered)
-        return GetUndefBooleanConstant();
-      [[fallthrough]];
-    case ISD::SETOLT:
-      return getBoolConstant(R == APFloat::cmpLessThan, dl, VT, OpVT);
-    case ISD::SETGT:
-      if (R == APFloat::cmpUnordered)
-        return GetUndefBooleanConstant();
-      [[fallthrough]];
-    case ISD::SETOGT:
-      return getBoolConstant(R == APFloat::cmpGreaterThan, dl, VT, OpVT);
-    case ISD::SETLE:
-      if (R == APFloat::cmpUnordered)
-        return GetUndefBooleanConstant();
-      [[fallthrough]];
-    case ISD::SETOLE:
-      return getBoolConstant(
-          R == APFloat::cmpLessThan || R == APFloat::cmpEqual, dl, VT, OpVT);
-    case ISD::SETGE:
-      if (R == APFloat::cmpUnordered)
-        return GetUndefBooleanConstant();
-      [[fallthrough]];
-    case ISD::SETOGE:
-      return getBoolConstant(
-          R == APFloat::cmpGreaterThan || R == APFloat::cmpEqual, dl, VT, OpVT);
-    case ISD::SETO:
-      return getBoolConstant(R != APFloat::cmpUnordered, dl, VT, OpVT);
-    case ISD::SETUO:
-      return getBoolConstant(R == APFloat::cmpUnordered, dl, VT, OpVT);
-    case ISD::SETUEQ:
-      return getBoolConstant(
-          R == APFloat::cmpUnordered || R == APFloat::cmpEqual, dl, VT, OpVT);
-    case ISD::SETUNE:
-      return getBoolConstant(R != APFloat::cmpEqual, dl, VT, OpVT);
-    case ISD::SETULT:
-      return getBoolConstant(R == APFloat::cmpUnordered ||
-                                 R == APFloat::cmpLessThan,
-                             dl, VT, OpVT);
-    case ISD::SETUGT:
-      return getBoolConstant(R == APFloat::cmpGreaterThan ||
-                                 R == APFloat::cmpUnordered,
-                             dl, VT, OpVT);
-    case ISD::SETULE:
-      return getBoolConstant(R != APFloat::cmpGreaterThan, dl, VT, OpVT);
-    case ISD::SETUGE:
-      return getBoolConstant(R != APFloat::cmpLessThan, dl, VT, OpVT);
+    default: break;
+    case ISD::SETEQ:  if (R==APFloat::cmpUnordered)
+                        return GetUndefBooleanConstant();
+                      [[fallthrough]];
+    case ISD::SETOEQ: return getBoolConstant(R==APFloat::cmpEqual, dl, VT,
+                                             OpVT);
+    case ISD::SETNE:  if (R==APFloat::cmpUnordered)
+                        return GetUndefBooleanConstant();
+                      [[fallthrough]];
+    case ISD::SETONE: return getBoolConstant(R==APFloat::cmpGreaterThan ||
+                                             R==APFloat::cmpLessThan, dl, VT,
+                                             OpVT);
+    case ISD::SETLT:  if (R==APFloat::cmpUnordered)
+                        return GetUndefBooleanConstant();
+                      [[fallthrough]];
+    case ISD::SETOLT: return getBoolConstant(R==APFloat::cmpLessThan, dl, VT,
+                                             OpVT);
+    case ISD::SETGT:  if (R==APFloat::cmpUnordered)
+                        return GetUndefBooleanConstant();
+                      [[fallthrough]];
+    case ISD::SETOGT: return getBoolConstant(R==APFloat::cmpGreaterThan, dl,
+                                             VT, OpVT);
+    case ISD::SETLE:  if (R==APFloat::cmpUnordered)
+                        return GetUndefBooleanConstant();
+                      [[fallthrough]];
+    case ISD::SETOLE: return getBoolConstant(R==APFloat::cmpLessThan ||
+                                             R==APFloat::cmpEqual, dl, VT,
+                                             OpVT);
+    case ISD::SETGE:  if (R==APFloat::cmpUnordered)
+                        return GetUndefBooleanConstant();
+                      [[fallthrough]];
+    case ISD::SETOGE: return getBoolConstant(R==APFloat::cmpGreaterThan ||
+                                         R==APFloat::cmpEqual, dl, VT, OpVT);
+    case ISD::SETO:   return getBoolConstant(R!=APFloat::cmpUnordered, dl, VT,
+                                             OpVT);
+    case ISD::SETUO:  return getBoolConstant(R==APFloat::cmpUnordered, dl, VT,
+                                             OpVT);
+    case ISD::SETUEQ: return getBoolConstant(R==APFloat::cmpUnordered ||
+                                             R==APFloat::cmpEqual, dl, VT,
+                                             OpVT);
+    case ISD::SETUNE: return getBoolConstant(R!=APFloat::cmpEqual, dl, VT,
+                                             OpVT);
+    case ISD::SETULT: return getBoolConstant(R==APFloat::cmpUnordered ||
+                                             R==APFloat::cmpLessThan, dl, VT,
+                                             OpVT);
+    case ISD::SETUGT: return getBoolConstant(R==APFloat::cmpGreaterThan ||
+                                             R==APFloat::cmpUnordered, dl, VT,
+                                             OpVT);
+    case ISD::SETULE: return getBoolConstant(R!=APFloat::cmpGreaterThan, dl,
+                                             VT, OpVT);
+    case ISD::SETUGE: return getBoolConstant(R!=APFloat::cmpLessThan, dl, VT,
+                                             OpVT);
     }
   } else if (N1CFP && OpVT.isSimple() && !N2.isUndef()) {
     // Ensure that the constant occurs on the RHS.
@@ -3168,8 +3135,8 @@ bool SelectionDAG::isSplatValue(SDValue V, bool AllowUndefs) const {
   // Since the number of lanes in a scalable vector is unknown at compile time,
   // we track one bit which is implicitly broadcast to all lanes.  This means
   // that all lanes in a scalable vector are considered demanded.
-  APInt DemandedElts =
-      APInt::getAllOnes(VT.isScalableVector() ? 1 : VT.getVectorNumElements());
+  APInt DemandedElts
+    = APInt::getAllOnes(VT.isScalableVector() ? 1 : VT.getVectorNumElements());
   return isSplatValue(V, DemandedElts, UndefElts) &&
          (AllowUndefs || !UndefElts);
 }
@@ -3182,11 +3149,11 @@ SDValue SelectionDAG::getSplatSourceVector(SDValue V, int &SplatIdx) {
   switch (Opcode) {
   default: {
     APInt UndefElts;
-    // Since the number of lanes in a scalable vector is unknown at compile
-    // time, we track one bit which is implicitly broadcast to all lanes.  This
-    // means that all lanes in a scalable vector are considered demanded.
-    APInt DemandedElts = APInt::getAllOnes(
-        VT.isScalableVector() ? 1 : VT.getVectorNumElements());
+    // Since the number of lanes in a scalable vector is unknown at compile time,
+    // we track one bit which is implicitly broadcast to all lanes.  This means
+    // that all lanes in a scalable vector are considered demanded.
+    APInt DemandedElts
+      = APInt::getAllOnes(VT.isScalableVector() ? 1 : VT.getVectorNumElements());
 
     if (isSplatValue(V, DemandedElts, UndefElts)) {
       if (VT.isScalableVector()) {
@@ -3378,7 +3345,7 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
                                          unsigned Depth) const {
   unsigned BitWidth = Op.getScalarValueSizeInBits();
 
-  KnownBits Known(BitWidth); // Don't know anything.
+  KnownBits Known(BitWidth);   // Don't know anything.
 
   if (auto OptAPInt = Op->bitcastToAPInt()) {
     // We know all of the bits for a constant!
@@ -3386,7 +3353,7 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
   }
 
   if (Depth >= MaxRecursionDepth)
-    return Known; // Limit search depth.
+    return Known;  // Limit search depth.
 
   KnownBits Known2;
   unsigned NumElts = DemandedElts.getBitWidth();
@@ -3397,7 +3364,7 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
          "Unexpected vector size");
 
   if (!DemandedElts)
-    return Known; // No demanded elts, better to assume we don't know anything.
+    return Known;  // No demanded elts, better to assume we don't know anything.
 
   unsigned Opcode = Op.getOpcode();
   switch (Opcode) {
@@ -3632,7 +3599,8 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
           SubDemandedElts.setBit(i * SubScale);
 
       for (unsigned i = 0; i != SubScale; ++i) {
-        Known2 = computeKnownBits(N0, SubDemandedElts.shl(i), Depth + 1);
+        Known2 = computeKnownBits(N0, SubDemandedElts.shl(i),
+                         Depth + 1);
         unsigned Shifts = IsLE ? i : SubScale - 1 - i;
         Known.insertBits(Known2, SubBitWidth * Shifts);
       }
@@ -3695,7 +3663,8 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
     // with itself is non-negative. Only do this if we didn't already computed
     // the opposite value for the sign bit.
     if (Op->getFlags().hasNoSignedWrap() &&
-        Op.getOperand(0) == Op.getOperand(1) && !Known.isNegative())
+        Op.getOperand(0) == Op.getOperand(1) &&
+        !Known.isNegative())
       Known.makeNonNegative();
     break;
   }
@@ -3778,21 +3747,21 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
   }
   case ISD::SELECT:
   case ISD::VSELECT:
-    Known = computeKnownBits(Op.getOperand(2), DemandedElts, Depth + 1);
+    Known = computeKnownBits(Op.getOperand(2), DemandedElts, Depth+1);
     // If we don't know any bits, early out.
     if (Known.isUnknown())
       break;
-    Known2 = computeKnownBits(Op.getOperand(1), DemandedElts, Depth + 1);
+    Known2 = computeKnownBits(Op.getOperand(1), DemandedElts, Depth+1);
 
     // Only known if known in both the LHS and RHS.
     Known = Known.intersectWith(Known2);
     break;
   case ISD::SELECT_CC:
-    Known = computeKnownBits(Op.getOperand(3), DemandedElts, Depth + 1);
+    Known = computeKnownBits(Op.getOperand(3), DemandedElts, Depth+1);
     // If we don't know any bits, early out.
     if (Known.isUnknown())
       break;
-    Known2 = computeKnownBits(Op.getOperand(2), DemandedElts, Depth + 1);
+    Known2 = computeKnownBits(Op.getOperand(2), DemandedElts, Depth+1);
 
     // Only known if known in both the LHS and RHS.
     Known = Known.intersectWith(Known2);
@@ -3874,8 +3843,7 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
     break;
   case ISD::FSHL:
   case ISD::FSHR:
-    if (ConstantSDNode *C =
-            isConstOrConstSplat(Op.getOperand(2), DemandedElts)) {
+    if (ConstantSDNode *C = isConstOrConstSplat(Op.getOperand(2), DemandedElts)) {
       unsigned Amt = C->getAPIntValue().urem(BitWidth);
 
       // For fshl, 0-shift returns the 1st arg.
@@ -4134,7 +4102,7 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
     APInt InMask = APInt::getLowBitsSet(BitWidth, VT.getSizeInBits());
     Known = computeKnownBits(Op.getOperand(0), DemandedElts, Depth + 1);
     Known.Zero |= (~InMask);
-    Known.One &= (~Known.Zero);
+    Known.One  &= (~Known.Zero);
     break;
   }
   case ISD::AssertAlign: {
@@ -4273,13 +4241,12 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
     break;
   }
   case ISD::EXTRACT_ELEMENT: {
-    Known = computeKnownBits(Op.getOperand(0), Depth + 1);
+    Known = computeKnownBits(Op.getOperand(0), Depth+1);
     const unsigned Index = Op.getConstantOperandVal(1);
     const unsigned EltBitWidth = Op.getValueSizeInBits();
 
     // Remove low part of known bits mask
-    Known.Zero =
-        Known.Zero.getHiBits(Known.getBitWidth() - Index * EltBitWidth);
+    Known.Zero = Known.Zero.getHiBits(Known.getBitWidth() - Index * EltBitWidth);
     Known.One = Known.One.getHiBits(Known.getBitWidth() - Index * EltBitWidth);
 
     // Remove high part of known bit mask
@@ -4548,8 +4515,7 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
 }
 
 /// Convert ConstantRange OverflowResult into SelectionDAG::OverflowKind.
-static SelectionDAG::OverflowKind
-mapOverflowResult(ConstantRange::OverflowResult OR) {
+static SelectionDAG::OverflowKind mapOverflowResult(ConstantRange::OverflowResult OR) {
   switch (OR) {
   case ConstantRange::OverflowResult::MayOverflow:
     return SelectionDAG::OFK_Sometime;
@@ -4840,21 +4806,20 @@ unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, const APInt &DemandedElts,
   }
 
   if (Depth >= MaxRecursionDepth)
-    return 1; // Limit search depth.
+    return 1;  // Limit search depth.
 
   if (!DemandedElts)
-    return 1; // No demanded elts, better to assume we don't know anything.
+    return 1;  // No demanded elts, better to assume we don't know anything.
 
   unsigned Opcode = Op.getOpcode();
   switch (Opcode) {
-  default:
-    break;
+  default: break;
   case ISD::AssertSext:
     Tmp = cast<VTSDNode>(Op.getOperand(1))->getVT().getSizeInBits();
-    return VTBits - Tmp + 1;
+    return VTBits-Tmp+1;
   case ISD::AssertZext:
     Tmp = cast<VTSDNode>(Op.getOperand(1))->getVT().getSizeInBits();
-    return VTBits - Tmp;
+    return VTBits-Tmp;
   case ISD::FREEZE:
     if (isGuaranteedNotToBeUndefOrPoison(Op.getOperand(0), DemandedElts,
                                          /*PoisonOnly=*/false))
@@ -4985,12 +4950,12 @@ unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, const APInt &DemandedElts,
     return VTBits - Tmp + 1;
   case ISD::SIGN_EXTEND:
     Tmp = VTBits - Op.getOperand(0).getScalarValueSizeInBits();
-    return ComputeNumSignBits(Op.getOperand(0), DemandedElts, Depth + 1) + Tmp;
+    return ComputeNumSignBits(Op.getOperand(0), DemandedElts, Depth+1) + Tmp;
   case ISD::SIGN_EXTEND_INREG:
     // Max of the input and what this extends.
     Tmp = cast<VTSDNode>(Op.getOperand(1))->getVT().getScalarSizeInBits();
-    Tmp = VTBits - Tmp + 1;
-    Tmp2 = ComputeNumSignBits(Op.getOperand(0), DemandedElts, Depth + 1);
+    Tmp = VTBits-Tmp+1;
+    Tmp2 = ComputeNumSignBits(Op.getOperand(0), DemandedElts, Depth+1);
     return std::max(Tmp, Tmp2);
   case ISD::SIGN_EXTEND_VECTOR_INREG: {
     if (VT.isScalableVector())
@@ -4999,7 +4964,7 @@ unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, const APInt &DemandedElts,
     EVT SrcVT = Src.getValueType();
     APInt DemandedSrcElts = DemandedElts.zext(SrcVT.getVectorNumElements());
     Tmp = VTBits - SrcVT.getScalarSizeInBits();
-    return ComputeNumSignBits(Src, DemandedSrcElts, Depth + 1) + Tmp;
+    return ComputeNumSignBits(Src, DemandedSrcElts, Depth+1) + Tmp;
   }
   case ISD::SRA:
     Tmp = ComputeNumSignBits(Op.getOperand(0), DemandedElts, Depth + 1);
@@ -5040,11 +5005,11 @@ unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, const APInt &DemandedElts,
     break;
   case ISD::AND:
   case ISD::OR:
-  case ISD::XOR: // NOT is handled here.
+  case ISD::XOR:    // NOT is handled here.
     // Logical binary ops preserve the number of sign bits at the worst.
-    Tmp = ComputeNumSignBits(Op.getOperand(0), DemandedElts, Depth + 1);
+    Tmp = ComputeNumSignBits(Op.getOperand(0), DemandedElts, Depth+1);
     if (Tmp != 1) {
-      Tmp2 = ComputeNumSignBits(Op.getOperand(1), DemandedElts, Depth + 1);
+      Tmp2 = ComputeNumSignBits(Op.getOperand(1), DemandedElts, Depth+1);
       FirstAnswer = std::min(Tmp, Tmp2);
       // We computed what we know about the sign bits as our first
       // answer. Now proceed to the generic code that uses
@@ -5054,16 +5019,14 @@ unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, const APInt &DemandedElts,
 
   case ISD::SELECT:
   case ISD::VSELECT:
-    Tmp = ComputeNumSignBits(Op.getOperand(1), DemandedElts, Depth + 1);
-    if (Tmp == 1)
-      return 1; // Early out.
-    Tmp2 = ComputeNumSignBits(Op.getOperand(2), DemandedElts, Depth + 1);
+    Tmp = ComputeNumSignBits(Op.getOperand(1), DemandedElts, Depth+1);
+    if (Tmp == 1) return 1;  // Early out.
+    Tmp2 = ComputeNumSignBits(Op.getOperand(2), DemandedElts, Depth+1);
     return std::min(Tmp, Tmp2);
   case ISD::SELECT_CC:
-    Tmp = ComputeNumSignBits(Op.getOperand(2), DemandedElts, Depth + 1);
-    if (Tmp == 1)
-      return 1; // Early out.
-    Tmp2 = ComputeNumSignBits(Op.getOperand(3), DemandedElts, Depth + 1);
+    Tmp = ComputeNumSignBits(Op.getOperand(2), DemandedElts, Depth+1);
+    if (Tmp == 1) return 1;  // Early out.
+    Tmp2 = ComputeNumSignBits(Op.getOperand(3), DemandedElts, Depth+1);
     return std::min(Tmp, Tmp2);
 
   case ISD::SMIN:
@@ -5089,7 +5052,7 @@ unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, const APInt &DemandedElts,
     // Fallback - just get the minimum number of sign bits of the operands.
     Tmp = ComputeNumSignBits(Op.getOperand(0), DemandedElts, Depth + 1);
     if (Tmp == 1)
-      return 1; // Early out.
+      return 1;  // Early out.
     Tmp2 = ComputeNumSignBits(Op.getOperand(1), DemandedElts, Depth + 1);
     return std::min(Tmp, Tmp2);
   }
@@ -5097,7 +5060,7 @@ unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, const APInt &DemandedElts,
   case ISD::UMAX:
     Tmp = ComputeNumSignBits(Op.getOperand(0), DemandedElts, Depth + 1);
     if (Tmp == 1)
-      return 1; // Early out.
+      return 1;  // Early out.
     Tmp2 = ComputeNumSignBits(Op.getOperand(1), DemandedElts, Depth + 1);
     return std::min(Tmp, Tmp2);
   case ISD::SSUBO_CARRY:
@@ -5153,16 +5116,14 @@ unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, const APInt &DemandedElts,
 
       // If we aren't rotating out all of the known-in sign bits, return the
       // number that are left.  This handles rotl(sext(x), 1) for example.
-      if (Tmp > (RotAmt + 1))
-        return (Tmp - RotAmt);
+      if (Tmp > (RotAmt + 1)) return (Tmp - RotAmt);
     }
     break;
   case ISD::ADD:
   case ISD::ADDC:
     // TODO: Move Operand 1 check before Operand 0 check
     Tmp = ComputeNumSignBits(Op.getOperand(0), DemandedElts, Depth + 1);
-    if (Tmp == 1)
-      return 1; // Early out.
+    if (Tmp == 1) return 1; // Early out.
 
     // Special case decrementing a value (ADD X, -1):
     if (ConstantSDNode *CRHS =
@@ -5183,16 +5144,14 @@ unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, const APInt &DemandedElts,
       }
 
     Tmp2 = ComputeNumSignBits(Op.getOperand(1), DemandedElts, Depth + 1);
-    if (Tmp2 == 1)
-      return 1; // Early out.
+    if (Tmp2 == 1) return 1; // Early out.
 
     // Add can have at most one carry bit.  Thus we know that the output
     // is, at worst, one more bit than the inputs.
     return std::min(Tmp, Tmp2) - 1;
   case ISD::SUB:
     Tmp2 = ComputeNumSignBits(Op.getOperand(1), DemandedElts, Depth + 1);
-    if (Tmp2 == 1)
-      return 1; // Early out.
+    if (Tmp2 == 1) return 1; // Early out.
 
     // Handle NEG.
     if (ConstantSDNode *CLHS =
@@ -5216,8 +5175,7 @@ unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, const APInt &DemandedElts,
     // Sub can have at most one carry bit.  Thus we know that the output
     // is, at worst, one more bit than the inputs.
     Tmp = ComputeNumSignBits(Op.getOperand(0), DemandedElts, Depth + 1);
-    if (Tmp == 1)
-      return 1; // Early out.
+    if (Tmp == 1) return 1; // Early out.
     return std::min(Tmp, Tmp2) - 1;
   case ISD::MUL: {
     // The output of the Mul can be at most twice the valid bits in the inputs.
@@ -5255,7 +5213,7 @@ unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, const APInt &DemandedElts,
   case ISD::EXTRACT_ELEMENT: {
     if (VT.isScalableVector())
       break;
-    const int KnownSign = ComputeNumSignBits(Op.getOperand(0), Depth + 1);
+    const int KnownSign = ComputeNumSignBits(Op.getOperand(0), Depth+1);
     const int BitWidth = Op.getValueSizeInBits();
     const int Items = Op.getOperand(0).getValueSizeInBits() / BitWidth;
 
@@ -5505,13 +5463,15 @@ unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, const APInt &DemandedElts,
   }
 
   // Allow the target to implement this method for its nodes.
-  if (Opcode >= ISD::BUILTIN_OP_END || Opcode == ISD::INTRINSIC_WO_CHAIN ||
-      Opcode == ISD::INTRINSIC_W_CHAIN || Opcode == ISD::INTRINSIC_VOID) {
+  if (Opcode >= ISD::BUILTIN_OP_END ||
+      Opcode == ISD::INTRINSIC_WO_CHAIN ||
+      Opcode == ISD::INTRINSIC_W_CHAIN ||
+      Opcode == ISD::INTRINSIC_VOID) {
     // TODO: This can probably be removed once target code is audited.  This
     // is here purely to reduce patch size and review complexity.
     if (!VT.isScalableVector()) {
       unsigned NumBits =
-          TLI->ComputeNumSignBitsForTargetNode(Op, DemandedElts, *this, Depth);
+        TLI->ComputeNumSignBitsForTargetNode(Op, DemandedElts, *this, Depth);
       if (NumBits > 1)
         FirstAnswer = std::max(FirstAnswer, NumBits);
     }
@@ -6175,7 +6135,8 @@ bool SelectionDAG::isKnownNeverNaN(SDValue Op, const APInt &DemandedElts,
 }
 
 bool SelectionDAG::isKnownNeverZeroFloat(SDValue Op) const {
-  assert(Op.getValueType().isFloatingPoint() && "Floating point type expected");
+  assert(Op.getValueType().isFloatingPoint() &&
+         "Floating point type expected");
 
   // If the value is a constant, we can obviously see if it is a zero or not.
   return ISD::matchUnaryFpPredicate(
@@ -6437,14 +6398,12 @@ bool SelectionDAG::canIgnoreSignBitOfZero(SDValue Op) const {
 
 bool SelectionDAG::isEqualTo(SDValue A, SDValue B) const {
   // Check the obvious case.
-  if (A == B)
-    return true;
+  if (A == B) return true;
 
   // For negative and positive zero.
   if (const ConstantFPSDNode *CA = dyn_cast<ConstantFPSDNode>(A))
     if (const ConstantFPSDNode *CB = dyn_cast<ConstantFPSDNode>(B))
-      if (CA->isZero() && CB->isZero())
-        return true;
+      if (CA->isZero() && CB->isZero()) return true;
 
   // Otherwise they may not be equal.
   return false;
@@ -6521,7 +6480,8 @@ static SDValue FoldSTEP_VECTOR(const SDLoc &DL, EVT VT, SDValue Step,
   return SDValue();
 }
 
-static SDValue FoldBUILD_VECTOR(const SDLoc &DL, EVT VT, ArrayRef<SDValue> Ops,
+static SDValue FoldBUILD_VECTOR(const SDLoc &DL, EVT VT,
+                                ArrayRef<SDValue> Ops,
                                 SelectionDAG &DAG) {
   int NumOps = Ops.size();
   assert(NumOps != 0 && "Can't build an empty vector!");
@@ -6557,7 +6517,8 @@ static SDValue FoldBUILD_VECTOR(const SDLoc &DL, EVT VT, ArrayRef<SDValue> Ops,
 /// Try to simplify vector concatenation to an input value, undef, or build
 /// vector.
 static SDValue foldCONCAT_VECTORS(const SDLoc &DL, EVT VT,
-                                  ArrayRef<SDValue> Ops, SelectionDAG &DAG) {
+                                  ArrayRef<SDValue> Ops,
+                                  SelectionDAG &DAG) {
   assert(!Ops.empty() && "Can't concatenate an empty list of vectors!");
   assert(llvm::all_of(Ops,
                       [Ops](SDValue Op) {
@@ -6733,7 +6694,7 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
   case ISD::TokenFactor:
   case ISD::MERGE_VALUES:
   case ISD::CONCAT_VECTORS:
-    return N1; // Factor, merge or concat of one node?  No need.
+    return N1;         // Factor, merge or concat of one node?  No need.
   case ISD::BUILD_VECTOR: {
     // Attempt to simplify BUILD_VECTOR.
     SDValue Ops[] = {N1};
@@ -6741,13 +6702,11 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
       return V;
     break;
   }
-  case ISD::FP_ROUND:
-    llvm_unreachable("Invalid method to make FP_ROUND node");
+  case ISD::FP_ROUND: llvm_unreachable("Invalid method to make FP_ROUND node");
   case ISD::FP_EXTEND:
     assert(VT.isFloatingPoint() && N1.getValueType().isFloatingPoint() &&
            "Invalid FP cast!");
-    if (N1.getValueType() == VT)
-      return N1; // noop conversion.
+    if (N1.getValueType() == VT) return N1;  // noop conversion.
     assert((!VT.isVector() || VT.getVectorElementCount() ==
                                   N1.getValueType().getVectorElementCount()) &&
            "Vector element count mismatch!");
@@ -6772,8 +6731,7 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
     assert(VT.isVector() == N1.getValueType().isVector() &&
            "SIGN_EXTEND result type type should be vector iff the operand "
            "type is vector!");
-    if (N1.getValueType() == VT)
-      return N1; // noop extension
+    if (N1.getValueType() == VT) return N1;   // noop extension
     assert((!VT.isVector() || VT.getVectorElementCount() ==
                                   N1.getValueType().getVectorElementCount()) &&
            "Vector element count mismatch!");
@@ -6814,8 +6772,7 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
     assert(VT.isVector() == N1.getValueType().isVector() &&
            "ZERO_EXTEND result type type should be vector iff the operand "
            "type is vector!");
-    if (N1.getValueType() == VT)
-      return N1; // noop extension
+    if (N1.getValueType() == VT) return N1;   // noop extension
     assert((!VT.isVector() || VT.getVectorElementCount() ==
                                   N1.getValueType().getVectorElementCount()) &&
            "Vector element count mismatch!");
@@ -6860,8 +6817,7 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
     assert(VT.isVector() == N1.getValueType().isVector() &&
            "ANY_EXTEND result type type should be vector iff the operand "
            "type is vector!");
-    if (N1.getValueType() == VT)
-      return N1; // noop extension
+    if (N1.getValueType() == VT) return N1;   // noop extension
     assert((!VT.isVector() || VT.getVectorElementCount() ==
                                   N1.getValueType().getVectorElementCount()) &&
            "Vector element count mismatch!");
@@ -6893,8 +6849,7 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
     assert(VT.isVector() == N1.getValueType().isVector() &&
            "TRUNCATE result type type should be vector iff the operand "
            "type is vector!");
-    if (N1.getValueType() == VT)
-      return N1; // noop truncate
+    if (N1.getValueType() == VT) return N1;   // noop truncate
     assert((!VT.isVector() || VT.getVectorElementCount() ==
                                   N1.getValueType().getVectorElementCount()) &&
            "Vector element count mismatch!");
@@ -6954,8 +6909,7 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
   case ISD::BITCAST:
     assert(VT.getSizeInBits() == N1.getValueSizeInBits() &&
            "Cannot BITCAST between types of different sizes!");
-    if (VT == N1.getValueType())
-      return N1;                  // noop conversion.
+    if (VT == N1.getValueType()) return N1;   // noop conversion.
     if (OpOpcode == ISD::BITCAST) // bitconv(bitconv(x)) -> bitconv(x)
       return getNode(ISD::BITCAST, DL, VT, N1.getOperand(0));
     if (N1.isUndef())
@@ -7062,48 +7016,27 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
 static std::optional<APInt> FoldValue(unsigned Opcode, const APInt &C1,
                                       const APInt &C2) {
   switch (Opcode) {
-  case ISD::ADD:
-    return C1 + C2;
-  case ISD::SUB:
-    return C1 - C2;
-  case ISD::MUL:
-    return C1 * C2;
-  case ISD::AND:
-    return C1 & C2;
-  case ISD::OR:
-    return C1 | C2;
-  case ISD::XOR:
-    return C1 ^ C2;
-  case ISD::SHL:
-    return C1 << C2;
-  case ISD::SRL:
-    return C1.lshr(C2);
-  case ISD::SRA:
-    return C1.ashr(C2);
-  case ISD::ROTL:
-    return C1.rotl(C2);
-  case ISD::ROTR:
-    return C1.rotr(C2);
-  case ISD::SMIN:
-    return C1.sle(C2) ? C1 : C2;
-  case ISD::SMAX:
-    return C1.sge(C2) ? C1 : C2;
-  case ISD::UMIN:
-    return C1.ule(C2) ? C1 : C2;
-  case ISD::UMAX:
-    return C1.uge(C2) ? C1 : C2;
-  case ISD::SADDSAT:
-    return C1.sadd_sat(C2);
-  case ISD::UADDSAT:
-    return C1.uadd_sat(C2);
-  case ISD::SSUBSAT:
-    return C1.ssub_sat(C2);
-  case ISD::USUBSAT:
-    return C1.usub_sat(C2);
-  case ISD::SSHLSAT:
-    return C1.sshl_sat(C2);
-  case ISD::USHLSAT:
-    return C1.ushl_sat(C2);
+  case ISD::ADD:  return C1 + C2;
+  case ISD::SUB:  return C1 - C2;
+  case ISD::MUL:  return C1 * C2;
+  case ISD::AND:  return C1 & C2;
+  case ISD::OR:   return C1 | C2;
+  case ISD::XOR:  return C1 ^ C2;
+  case ISD::SHL:  return C1 << C2;
+  case ISD::SRL:  return C1.lshr(C2);
+  case ISD::SRA:  return C1.ashr(C2);
+  case ISD::ROTL: return C1.rotl(C2);
+  case ISD::ROTR: return C1.rotr(C2);
+  case ISD::SMIN: return C1.sle(C2) ? C1 : C2;
+  case ISD::SMAX: return C1.sge(C2) ? C1 : C2;
+  case ISD::UMIN: return C1.ule(C2) ? C1 : C2;
+  case ISD::UMAX: return C1.uge(C2) ? C1 : C2;
+  case ISD::SADDSAT: return C1.sadd_sat(C2);
+  case ISD::UADDSAT: return C1.uadd_sat(C2);
+  case ISD::SSUBSAT: return C1.ssub_sat(C2);
+  case ISD::USUBSAT: return C1.usub_sat(C2);
+  case ISD::SSHLSAT: return C1.sshl_sat(C2);
+  case ISD::USHLSAT: return C1.ushl_sat(C2);
   case ISD::UDIV:
     if (!C2.getBoolValue())
       break;
@@ -7176,11 +7109,8 @@ SDValue SelectionDAG::FoldSymbolOffset(unsigned Opcode, EVT VT,
   case ISD::ADD:
   case ISD::PTRADD:
     break;
-  case ISD::SUB:
-    Offset = -uint64_t(Offset);
-    break;
-  default:
-    return SDValue();
+  case ISD::SUB: Offset = -uint64_t(Offset); break;
+  default: return SDValue();
   }
   return getGlobalAddress(GA->getGlobal(), SDLoc(C2), VT,
                           GA->getOffset() + uint64_t(Offset));
@@ -7200,9 +7130,9 @@ bool SelectionDAG::isUndef(unsigned Opcode, ArrayRef<SDValue> Ops) {
       return true;
 
     return ISD::isBuildVectorOfConstantSDNodes(Divisor.getNode()) &&
-           llvm::any_of(Divisor->op_values(), [](SDValue V) {
-             return V.isUndef() || isNullConstant(V);
-           });
+           llvm::any_of(Divisor->op_values(),
+                        [](SDValue V) { return V.isUndef() ||
+                                        isNullConstant(V); });
     // TODO: Handle signed overflow.
   }
   // TODO: Handle oversized shifts.
@@ -7731,12 +7661,11 @@ SDValue SelectionDAG::foldConstantFPMath(unsigned Opcode, const SDLoc &DL,
       return getConstantFP(minimumnum(C1, C2), DL, VT);
     case ISD::FMAXIMUMNUM:
       return getConstantFP(maximumnum(C1, C2), DL, VT);
-    default:
-      break;
+    default: break;
     }
   }
   if (N1CFP && Opcode == ISD::FP_ROUND) {
-    APFloat C1 = N1CFP->getValueAPF(); // make copy
+    APFloat C1 = N1CFP->getValueAPF();    // make copy
     bool Unused;
     // This can return overflow, underflow, or inexact; we don't care.
     // FIXME need to be more flexible about rounding mode.
@@ -7900,7 +7829,8 @@ void SelectionDAG::canonicalizeCommutativeBinop(unsigned Opcode, SDValue &N1,
 SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
                               SDValue N1, SDValue N2, const SDNodeFlags Flags) {
   assert(N1.getOpcode() != ISD::DELETED_NODE &&
-         N2.getOpcode() != ISD::DELETED_NODE && "Operand is DELETED_NODE!");
+         N2.getOpcode() != ISD::DELETED_NODE &&
+         "Operand is DELETED_NODE!");
 
   canonicalizeCommutativeBinop(Opcode, N1, N2);
 
@@ -7913,18 +7843,14 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
       isConstOrConstSplat(N2, /*AllowUndefs*/ false, /*AllowTruncation*/ true);
 
   switch (Opcode) {
-  default:
-    break;
+  default: break;
   case ISD::TokenFactor:
     assert(VT == MVT::Other && N1.getValueType() == MVT::Other &&
            N2.getValueType() == MVT::Other && "Invalid token factor!");
     // Fold trivial token factors.
-    if (N1.getOpcode() == ISD::EntryToken)
-      return N2;
-    if (N2.getOpcode() == ISD::EntryToken)
-      return N1;
-    if (N1 == N2)
-      return N1;
+    if (N1.getOpcode() == ISD::EntryToken) return N2;
+    if (N2.getOpcode() == ISD::EntryToken) return N1;
+    if (N1 == N2) return N1;
     break;
   case ISD::BUILD_VECTOR: {
     // Attempt to simplify BUILD_VECTOR.
@@ -7941,8 +7867,8 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
   }
   case ISD::AND:
     assert(VT.isInteger() && "This operator does not apply to FP types!");
-    assert(N1.getValueType() == N2.getValueType() && N1.getValueType() == VT &&
-           "Binary operator types must match!");
+    assert(N1.getValueType() == N2.getValueType() &&
+           N1.getValueType() == VT && "Binary operator types must match!");
     // (X & 0) -> 0.  This commonly occurs when legalizing i64 values, so it's
     // worth handling here.
     if (N2CV && N2CV->isZero())
@@ -7956,8 +7882,8 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
   case ISD::PTRADD:
   case ISD::SUB:
     assert(VT.isInteger() && "This operator does not apply to FP types!");
-    assert(N1.getValueType() == N2.getValueType() && N1.getValueType() == VT &&
-           "Binary operator types must match!");
+    assert(N1.getValueType() == N2.getValueType() &&
+           N1.getValueType() == VT && "Binary operator types must match!");
     // The equal operand types requirement is unnecessarily strong for PTRADD.
     // However, the SelectionDAGBuilder does not generate PTRADDs with different
     // operand types, and we'd need to re-implement GEP's non-standard wrapping
@@ -7982,8 +7908,8 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
     break;
   case ISD::MUL:
     assert(VT.isInteger() && "This operator does not apply to FP types!");
-    assert(N1.getValueType() == N2.getValueType() && N1.getValueType() == VT &&
-           "Binary operator types must match!");
+    assert(N1.getValueType() == N2.getValueType() &&
+           N1.getValueType() == VT && "Binary operator types must match!");
     if (VT.getScalarType() == MVT::i1)
       return getNode(ISD::AND, DL, VT, N1, N2);
     if (N2CV && N2CV->isZero())
@@ -8005,8 +7931,8 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
   case ISD::UADDSAT:
   case ISD::USUBSAT:
     assert(VT.isInteger() && "This operator does not apply to FP types!");
-    assert(N1.getValueType() == N2.getValueType() && N1.getValueType() == VT &&
-           "Binary operator types must match!");
+    assert(N1.getValueType() == N2.getValueType() &&
+           N1.getValueType() == VT && "Binary operator types must match!");
     if (VT.getScalarType() == MVT::i1) {
       // fold (add_sat x, y) -> (or x, y) for bool types.
       if (Opcode == ISD::SADDSAT || Opcode == ISD::UADDSAT)
@@ -8032,30 +7958,30 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
   case ISD::AVGCEILS:
   case ISD::AVGCEILU:
     assert(VT.isInteger() && "This operator does not apply to FP types!");
-    assert(N1.getValueType() == N2.getValueType() && N1.getValueType() == VT &&
-           "Binary operator types must match!");
+    assert(N1.getValueType() == N2.getValueType() &&
+           N1.getValueType() == VT && "Binary operator types must match!");
     break;
   case ISD::ABDS:
   case ISD::ABDU:
     assert(VT.isInteger() && "This operator does not apply to FP types!");
-    assert(N1.getValueType() == N2.getValueType() && N1.getValueType() == VT &&
-           "Binary operator types must match!");
+    assert(N1.getValueType() == N2.getValueType() &&
+           N1.getValueType() == VT && "Binary operator types must match!");
     if (VT.getScalarType() == MVT::i1)
       return getNode(ISD::XOR, DL, VT, N1, N2);
     break;
   case ISD::SMIN:
   case ISD::UMAX:
     assert(VT.isInteger() && "This operator does not apply to FP types!");
-    assert(N1.getValueType() == N2.getValueType() && N1.getValueType() == VT &&
-           "Binary operator types must match!");
+    assert(N1.getValueType() == N2.getValueType() &&
+           N1.getValueType() == VT && "Binary operator types must match!");
     if (VT.getScalarType() == MVT::i1)
       return getNode(ISD::OR, DL, VT, N1, N2);
     break;
   case ISD::SMAX:
   case ISD::UMIN:
     assert(VT.isInteger() && "This operator does not apply to FP types!");
-    assert(N1.getValueType() == N2.getValueType() && N1.getValueType() == VT &&
-           "Binary operator types must match!");
+    assert(N1.getValueType() == N2.getValueType() &&
+           N1.getValueType() == VT && "Binary operator types must match!");
     if (VT.getScalarType() == MVT::i1)
       return getNode(ISD::AND, DL, VT, N1, N2);
     break;
@@ -8065,14 +7991,16 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
   case ISD::FDIV:
   case ISD::FREM:
     assert(VT.isFloatingPoint() && "This operator only applies to FP types!");
-    assert(N1.getValueType() == N2.getValueType() && N1.getValueType() == VT &&
-           "Binary operator types must match!");
+    assert(N1.getValueType() == N2.getValueType() &&
+           N1.getValueType() == VT && "Binary operator types must match!");
     if (SDValue V = simplifyFPBinop(Opcode, N1, N2, Flags))
       return V;
     break;
-  case ISD::FCOPYSIGN: // N1 and result must match.  N1/N2 need not match.
-    assert(N1.getValueType() == VT && N1.getValueType().isFloatingPoint() &&
-           N2.getValueType().isFloatingPoint() && "Invalid FCOPYSIGN!");
+  case ISD::FCOPYSIGN:   // N1 and result must match.  N1/N2 need not match.
+    assert(N1.getValueType() == VT &&
+           N1.getValueType().isFloatingPoint() &&
+           N2.getValueType().isFloatingPoint() &&
+           "Invalid FCOPYSIGN!");
     break;
   case ISD::SHL:
     if (N2C && (N1.getOpcode() == ISD::VSCALE) && Flags.hasNoSignedWrap()) {
@@ -8117,8 +8045,7 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
            VT.bitsLE(N1.getValueType()) && N2C &&
            (N2C->getZExtValue() == 0 || N2C->getZExtValue() == 1) &&
            N2.getOpcode() == ISD::TargetConstant && "Invalid FP_ROUND!");
-    if (N1.getValueType() == VT)
-      return N1; // noop conversion.
+    if (N1.getValueType() == VT) return N1;  // noop conversion.
     break;
   case ISD::AssertNoFPClass: {
     assert(N1.getValueType().isFloatingPoint() &&
@@ -8141,8 +8068,7 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
            "AssertSExt/AssertZExt type should be the vector element type "
            "rather than the vector type!");
     assert(EVT.bitsLE(VT.getScalarType()) && "Not extending!");
-    if (VT.getScalarType() == EVT)
-      return N1; // noop assertion.
+    if (VT.getScalarType() == EVT) return N1; // noop assertion.
     break;
   }
   case ISD::SIGN_EXTEND_INREG: {
@@ -8157,8 +8083,7 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
             EVT.getVectorElementCount() == VT.getVectorElementCount()) &&
            "Vector element counts must match in SIGN_EXTEND_INREG");
     assert(EVT.getScalarType().bitsLE(VT.getScalarType()) && "Not extending!");
-    if (EVT == VT)
-      return N1; // Not actually extending
+    if (EVT == VT) return N1;  // Not actually extending
     break;
   }
   case ISD::FP_TO_SINT_SAT:
@@ -8239,8 +8164,7 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
           if (VT == N1.getOperand(1).getValueType())
             return N1.getOperand(1);
           if (VT.isFloatingPoint()) {
-            assert(VT.getSizeInBits() >
-                   N1.getOperand(1).getValueType().getSizeInBits());
+            assert(VT.getSizeInBits() > N1.getOperand(1).getValueType().getSizeInBits());
             return getFPExtendOrRound(N1.getOperand(1), DL, VT);
           }
           return getSExtOrTrunc(N1.getOperand(1), DL, VT);
@@ -8268,7 +8192,8 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
     assert(N2C && (unsigned)N2C->getZExtValue() < 2 && "Bad EXTRACT_ELEMENT!");
     assert(!N1.getValueType().isVector() && !VT.isVector() &&
            (N1.getValueType().isInteger() == VT.isInteger()) &&
-           N1.getValueType() != VT && "Wrong types for EXTRACT_ELEMENT!");
+           N1.getValueType() != VT &&
+           "Wrong types for EXTRACT_ELEMENT!");
 
     // EXTRACT_ELEMENT of BUILD_PAIR is often formed while legalize is expanding
     // 64-bit integers into 32-bit parts.  Instead of building the extract of
@@ -8476,7 +8401,8 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
                               const SDNodeFlags Flags) {
   assert(N1.getOpcode() != ISD::DELETED_NODE &&
          N2.getOpcode() != ISD::DELETED_NODE &&
-         N3.getOpcode() != ISD::DELETED_NODE && "Operand is DELETED_NODE!");
+         N3.getOpcode() != ISD::DELETED_NODE &&
+         "Operand is DELETED_NODE!");
   // Perform various simplifications.
   switch (Opcode) {
   case ISD::BUILD_VECTOR: {
@@ -8733,7 +8659,7 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
 SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
                               SDValue N1, SDValue N2, SDValue N3, SDValue N4,
                               const SDNodeFlags Flags) {
-  SDValue Ops[] = {N1, N2, N3, N4};
+  SDValue Ops[] = { N1, N2, N3, N4 };
   return getNode(Opcode, DL, VT, Ops, Flags);
 }
 
@@ -8748,7 +8674,7 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
 SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
                               SDValue N1, SDValue N2, SDValue N3, SDValue N4,
                               SDValue N5, const SDNodeFlags Flags) {
-  SDValue Ops[] = {N1, N2, N3, N4, N5};
+  SDValue Ops[] = { N1, N2, N3, N4, N5 };
   return getNode(Opcode, DL, VT, Ops, Flags);
 }
 
@@ -8793,8 +8719,7 @@ static SDValue getMemsetValue(SDValue Value, EVT VT, SelectionDAG &DAG,
     assert(C->getAPIntValue().getBitWidth() == 8);
     APInt Val = APInt::getSplat(NumBits, C->getAPIntValue());
     if (VT.isInteger()) {
-      bool IsOpaque =
-          VT.getSizeInBits() > 64 ||
+      bool IsOpaque = VT.getSizeInBits() > 64 ||
           !DAG.getTargetLoweringInfo().isLegalStoreImmediate(C->getSExtValue());
       return DAG.getConstant(Val, dl, VT, false, IsOpaque);
     }
@@ -8845,10 +8770,10 @@ static SDValue getMemsetStringVal(EVT VT, const SDLoc &dl, SelectionDAG &DAG,
   APInt Val(NumVTBits, 0);
   if (DAG.getDataLayout().isLittleEndian()) {
     for (unsigned i = 0; i != NumBytes; ++i)
-      Val |= (uint64_t)(unsigned char)Slice[i] << i * 8;
+      Val |= (uint64_t)(unsigned char)Slice[i] << i*8;
   } else {
     for (unsigned i = 0; i != NumBytes; ++i)
-      Val |= (uint64_t)(unsigned char)Slice[i] << (NumVTBytes - i - 1) * 8;
+      Val |= (uint64_t)(unsigned char)Slice[i] << (NumVTBytes-i-1)*8;
   }
 
   // If the "cost" of materializing the integer immediate is less than the cost
@@ -8908,10 +8833,10 @@ static bool shouldLowerMemFuncForSize(const MachineFunction &MF,
   return DAG.shouldOptForSize();
 }
 
-static void chainLoadsAndStoresForMemcpy(
-    SelectionDAG &DAG, const SDLoc &dl, SmallVector<SDValue, 32> &OutChains,
-    unsigned From, unsigned To, SmallVector<SDValue, 16> &OutLoadChains,
-    SmallVector<SDValue, 16> &OutStoreChains) {
+static void chainLoadsAndStoresForMemcpy(SelectionDAG &DAG, const SDLoc &dl,
+                          SmallVector<SDValue, 32> &OutChains, unsigned From,
+                          unsigned To, SmallVector<SDValue, 16> &OutLoadChains,
+                          SmallVector<SDValue, 16> &OutStoreChains) {
   assert(OutLoadChains.size() && "Missing loads in memcpy inlining");
   assert(OutStoreChains.size() && "Missing stores in memcpy inlining");
   SmallVector<SDValue, 16> GluedLoadChains;
@@ -8921,14 +8846,14 @@ static void chainLoadsAndStoresForMemcpy(
   }
 
   // Chain for all loads.
-  SDValue LoadToken =
-      DAG.getNode(ISD::TokenFactor, dl, MVT::Other, GluedLoadChains);
+  SDValue LoadToken = DAG.getNode(ISD::TokenFactor, dl, MVT::Other,
+                                  GluedLoadChains);
 
   for (unsigned i = From; i < To; ++i) {
     StoreSDNode *ST = dyn_cast<StoreSDNode>(OutStoreChains[i]);
-    SDValue NewStore =
-        DAG.getTruncStore(LoadToken, dl, ST->getValue(), ST->getBasePtr(),
-                          ST->getMemoryVT(), ST->getMemOperand());
+    SDValue NewStore = DAG.getTruncStore(LoadToken, dl, ST->getValue(),
+                                  ST->getBasePtr(), ST->getMemoryVT(),
+                                  ST->getMemOperand());
     OutChains.push_back(NewStore);
   }
 }
@@ -9021,7 +8946,7 @@ static SDValue getMemcpyLoadsAndStores(
     if (VTSize > Size) {
       // Issuing an unaligned load / store pair  that overlaps with the previous
       // pair. Adjust the offset accordingly.
-      assert(i == NumMemOps - 1 && i != 0);
+      assert(i == NumMemOps-1 && i != 0);
       SrcOff -= VTSize - Size;
       DstOff -= VTSize - Size;
     }
@@ -9088,8 +9013,8 @@ static SDValue getMemcpyLoadsAndStores(
     Size -= VTSize;
   }
 
-  unsigned GluedLdStLimit =
-      MaxLdStGlue == 0 ? TLI.getMaxGluedStoresPerMemcpy() : MaxLdStGlue;
+  unsigned GluedLdStLimit = MaxLdStGlue == 0 ?
+                                TLI.getMaxGluedStoresPerMemcpy() : MaxLdStGlue;
   unsigned NumLdStInMemcpy = OutStoreChains.size();
 
   if (NumLdStInMemcpy) {
@@ -9105,10 +9030,11 @@ static SDValue getMemcpyLoadsAndStores(
     } else {
       // Ld/St less than/equal limit set by target.
       if (NumLdStInMemcpy <= GluedLdStLimit) {
-        chainLoadsAndStoresForMemcpy(DAG, dl, OutChains, 0, NumLdStInMemcpy,
-                                     OutLoadChains, OutStoreChains);
+          chainLoadsAndStoresForMemcpy(DAG, dl, OutChains, 0,
+                                        NumLdStInMemcpy, OutLoadChains,
+                                        OutStoreChains);
       } else {
-        unsigned NumberLdChain = NumLdStInMemcpy / GluedLdStLimit;
+        unsigned NumberLdChain =  NumLdStInMemcpy / GluedLdStLimit;
         unsigned RemainingLdStInMemcpy = NumLdStInMemcpy % GluedLdStLimit;
         unsigned GlueIter = 0;
 
@@ -9340,7 +9266,7 @@ static SDValue getMemsetStores(SelectionDAG &DAG, const SDLoc &dl,
     if (VTSize > Size) {
       // Issuing an unaligned load / store pair that overlaps with the previous
       // pair. Adjust the offset accordingly.
-      assert(i == NumMemOps - 1 && i != 0);
+      assert(i == NumMemOps-1 && i != 0);
       DstOff -= VTSize - Size;
     }
 
@@ -9621,7 +9547,7 @@ SDValue SelectionDAG::getMemcpy(
       .setDiscardResult()
       .setTailCall(IsTailCall);
 
-  std::pair<SDValue, SDValue> CallResult = TLI->LowerCallTo(CLI);
+  std::pair<SDValue,SDValue> CallResult = TLI->LowerCallTo(CLI);
   return CallResult.second;
 }
 
@@ -9727,7 +9653,7 @@ SDValue SelectionDAG::getMemmove(SDValue Chain, const SDLoc &dl, SDValue Dst,
       .setDiscardResult()
       .setTailCall(IsTailCall);
 
-  std::pair<SDValue, SDValue> CallResult = TLI->LowerCallTo(CLI);
+  std::pair<SDValue,SDValue> CallResult = TLI->LowerCallTo(CLI);
   return CallResult.second;
 }
 
@@ -9790,9 +9716,8 @@ SDValue SelectionDAG::getMemset(SDValue Chain, const SDLoc &dl, SDValue Dst,
   // Then check to see if we should lower the memset with target-specific
   // code. If the target chooses to do this, this is the next best.
   if (TSI) {
-    SDValue Result = TSI->EmitTargetCodeForMemset(*this, dl, Chain, Dst, Src,
-                                                  Size, Alignment, isVol,
-                                                  AlwaysInline, DstPtrInfo);
+    SDValue Result = TSI->EmitTargetCodeForMemset(
+        *this, dl, Chain, Dst, Src, Size, Alignment, isVol, AlwaysInline, DstPtrInfo);
     if (Result.getNode())
       return Result;
   }
@@ -9813,7 +9738,7 @@ SDValue SelectionDAG::getMemset(SDValue Chain, const SDLoc &dl, SDValue Dst,
 
   // Emit a library call.
   auto &Ctx = *getContext();
-  const auto &DL = getDataLayout();
+  const auto& DL = getDataLayout();
 
   TargetLowering::CallLoweringInfo CLI(*this);
   // FIXME: pass in SDLoc
@@ -9902,7 +9827,7 @@ SDValue SelectionDAG::getAtomic(unsigned Opcode, const SDLoc &dl, EVT MemVT,
       dl.getIROrder(), Opcode, VTList, MemVT, MMO, ExtType));
   ID.AddInteger(MMO->getPointerInfo().getAddrSpace());
   ID.AddInteger(MMO->getFlags());
-  void *IP = nullptr;
+  void* IP = nullptr;
   if (auto *E = cast_or_null<AtomicSDNode>(FindNodeOrInsertPos(ID, dl, IP))) {
     E->refineAlignment(MMO);
     E->refineRanges(MMO);
@@ -9954,8 +9879,8 @@ SDValue SelectionDAG::getAtomic(unsigned Opcode, const SDLoc &dl, EVT MemVT,
 
   EVT VT = Val.getValueType();
 
-  SDVTList VTs = Opcode == ISD::ATOMIC_STORE ? getVTList(MVT::Other)
-                                             : getVTList(VT, MVT::Other);
+  SDVTList VTs = Opcode == ISD::ATOMIC_STORE ? getVTList(MVT::Other) :
+                                               getVTList(VT, MVT::Other);
   SDValue Ops[] = {Chain, Ptr, Val};
   return getAtomic(Opcode, dl, MemVT, VTs, Ops, MMO);
 }
@@ -10032,7 +9957,7 @@ SDValue SelectionDAG::getMemIntrinsicNode(unsigned Opcode, const SDLoc &dl,
 
   // Memoize the node unless it returns a glue result.
   MemIntrinsicSDNode *N;
-  if (VTList.VTs[VTList.NumVTs - 1] != MVT::Glue) {
+  if (VTList.VTs[VTList.NumVTs-1] != MVT::Glue) {
     FoldingSetNodeID ID;
     AddNodeIDNode(ID, Opcode, VTList, Ops);
     ID.AddInteger(getSyntheticNodeSubclassData<MemIntrinsicSDNode>(
@@ -10127,7 +10052,8 @@ static MachinePointerInfo InferPointerInfo(const MachinePointerInfo &Info,
                                              FI->getIndex(), Offset);
 
   // If this is (FI+Offset1)+Offset2, we can model it.
-  if (Ptr.getOpcode() != ISD::ADD || !isa<ConstantSDNode>(Ptr.getOperand(1)) ||
+  if (Ptr.getOpcode() != ISD::ADD ||
+      !isa<ConstantSDNode>(Ptr.getOperand(1)) ||
       !isa<FrameIndexSDNode>(Ptr.getOperand(0)))
     return Info;
 
@@ -10159,7 +10085,8 @@ SDValue SelectionDAG::getLoad(ISD::MemIndexedMode AM, ISD::LoadExtType ExtType,
                               Align Alignment,
                               MachineMemOperand::Flags MMOFlags,
                               const AAMDNodes &AAInfo, const MDNode *Ranges) {
-  assert(Chain.getValueType() == MVT::Other && "Invalid chain type");
+  assert(Chain.getValueType() == MVT::Other &&
+        "Invalid chain type");
 
   MMOFlags |= MachineMemOperand::MOLoad;
   assert((MMOFlags & MachineMemOperand::MOStore) == 0);
@@ -10205,9 +10132,9 @@ SDValue SelectionDAG::getLoad(ISD::MemIndexedMode AM, ISD::LoadExtType ExtType,
   bool Indexed = AM != ISD::UNINDEXED;
   assert((Indexed || Offset.isUndef()) && "Unindexed load with an offset!");
 
-  SDVTList VTs = Indexed ? getVTList(VT, Ptr.getValueType(), MVT::Other)
-                         : getVTList(VT, MVT::Other);
-  SDValue Ops[] = {Chain, Ptr, Offset};
+  SDVTList VTs = Indexed ?
+    getVTList(VT, Ptr.getValueType(), MVT::Other) : getVTList(VT, MVT::Other);
+  SDValue Ops[] = { Chain, Ptr, Offset };
   FoldingSetNodeID ID;
   AddNodeIDNode(ID, ISD::LOAD, VTs, Ops);
   ID.AddInteger(MemVT.getRawBits());
@@ -10264,8 +10191,8 @@ SDValue SelectionDAG::getExtLoad(ISD::LoadExtType ExtType, const SDLoc &dl,
                                  EVT VT, SDValue Chain, SDValue Ptr, EVT MemVT,
                                  MachineMemOperand *MMO) {
   SDValue Undef = getUNDEF(Ptr.getValueType());
-  return getLoad(ISD::UNINDEXED, ExtType, VT, dl, Chain, Ptr, Undef, MemVT,
-                 MMO);
+  return getLoad(ISD::UNINDEXED, ExtType, VT, dl, Chain, Ptr, Undef,
+                 MemVT, MMO);
 }
 
 SDValue SelectionDAG::getIndexedLoad(SDValue OrigLoad, const SDLoc &dl,
@@ -10363,7 +10290,8 @@ SDValue SelectionDAG::getTruncStore(SDValue Chain, const SDLoc &dl, SDValue Val,
                                     EVT SVT, Align Alignment,
                                     MachineMemOperand::Flags MMOFlags,
                                     const AAMDNodes &AAInfo) {
-  assert(Chain.getValueType() == MVT::Other && "Invalid chain type");
+  assert(Chain.getValueType() == MVT::Other &&
+        "Invalid chain type");
 
   MMOFlags |= MachineMemOperand::MOStore;
   assert((MMOFlags & MachineMemOperand::MOLoad) == 0);
@@ -10931,7 +10859,8 @@ SDValue SelectionDAG::getMaskedStore(SDValue Chain, const SDLoc &dl,
                                      MachineMemOperand *MMO,
                                      ISD::MemIndexedMode AM, bool IsTruncating,
                                      bool IsCompressing) {
-  assert(Chain.getValueType() == MVT::Other && "Invalid chain type");
+  assert(Chain.getValueType() == MVT::Other &&
+        "Invalid chain type");
   bool Indexed = AM != ISD::UNINDEXED;
   assert((Indexed || Offset.isUndef()) &&
          "Unindexed masked store with an offset!");
@@ -11244,8 +11173,8 @@ SDValue SelectionDAG::simplifyFPBinop(unsigned Opcode, SDValue X, SDValue Y,
   // operation is poison. That result can be relaxed to undef.
   ConstantFPSDNode *XC = isConstOrConstSplatFP(X, /* AllowUndefs */ true);
   ConstantFPSDNode *YC = isConstOrConstSplatFP(Y, /* AllowUndefs */ true);
-  bool HasNan =
-      (XC && XC->getValueAPF().isNaN()) || (YC && YC->getValueAPF().isNaN());
+  bool HasNan = (XC && XC->getValueAPF().isNaN()) ||
+                (YC && YC->getValueAPF().isNaN());
   bool HasInf = (XC && XC->getValueAPF().isInfinity()) ||
                 (YC && YC->getValueAPF().isInfinity());
 
@@ -11284,23 +11213,18 @@ SDValue SelectionDAG::simplifyFPBinop(unsigned Opcode, SDValue X, SDValue Y,
 
 SDValue SelectionDAG::getVAArg(EVT VT, const SDLoc &dl, SDValue Chain,
                                SDValue Ptr, SDValue SV, unsigned Align) {
-  SDValue Ops[] = {Chain, Ptr, SV, getTargetConstant(Align, dl, MVT::i32)};
+  SDValue Ops[] = { Chain, Ptr, SV, getTargetConstant(Align, dl, MVT::i32) };
   return getNode(ISD::VAARG, dl, getVTList(VT, MVT::Other), Ops);
 }
 
 SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
                               ArrayRef<SDUse> Ops) {
   switch (Ops.size()) {
-  case 0:
-    return getNode(Opcode, DL, VT);
-  case 1:
-    return getNode(Opcode, DL, VT, Ops[0].get());
-  case 2:
-    return getNode(Opcode, DL, VT, Ops[0], Ops[1]);
-  case 3:
-    return getNode(Opcode, DL, VT, Ops[0], Ops[1], Ops[2]);
-  default:
-    break;
+  case 0: return getNode(Opcode, DL, VT);
+  case 1: return getNode(Opcode, DL, VT, Ops[0].get());
+  case 2: return getNode(Opcode, DL, VT, Ops[0], Ops[1]);
+  case 3: return getNode(Opcode, DL, VT, Ops[0], Ops[1], Ops[2]);
+  default: break;
   }
 
   // Copy from an SDUse array into an SDValue array for use with
@@ -11321,26 +11245,21 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
                               ArrayRef<SDValue> Ops, const SDNodeFlags Flags) {
   unsigned NumOps = Ops.size();
   switch (NumOps) {
-  case 0:
-    return getNode(Opcode, DL, VT);
-  case 1:
-    return getNode(Opcode, DL, VT, Ops[0], Flags);
-  case 2:
-    return getNode(Opcode, DL, VT, Ops[0], Ops[1], Flags);
-  case 3:
-    return getNode(Opcode, DL, VT, Ops[0], Ops[1], Ops[2], Flags);
-  default:
-    break;
+  case 0: return getNode(Opcode, DL, VT);
+  case 1: return getNode(Opcode, DL, VT, Ops[0], Flags);
+  case 2: return getNode(Opcode, DL, VT, Ops[0], Ops[1], Flags);
+  case 3: return getNode(Opcode, DL, VT, Ops[0], Ops[1], Ops[2], Flags);
+  default: break;
   }
 
 #ifndef NDEBUG
   for (const auto &Op : Ops)
-    assert(Op.getOpcode() != ISD::DELETED_NODE && "Operand is DELETED_NODE!");
+    assert(Op.getOpcode() != ISD::DELETED_NODE &&
+           "Operand is DELETED_NODE!");
 #endif
 
   switch (Opcode) {
-  default:
-    break;
+  default: break;
   case ISD::BUILD_VECTOR:
     // Attempt to simplify BUILD_VECTOR.
     if (SDValue V = FoldBUILD_VECTOR(DL, VT, Ops, *this))
@@ -11465,7 +11384,8 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList,
 
 #ifndef NDEBUG
   for (const auto &Op : Ops)
-    assert(Op.getOpcode() != ISD::DELETED_NODE && "Operand is DELETED_NODE!");
+    assert(Op.getOpcode() != ISD::DELETED_NODE &&
+           "Operand is DELETED_NODE!");
 #endif
 
   switch (Opcode) {
@@ -11606,7 +11526,7 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList,
 
   // Memoize the node unless it returns a glue result.
   SDNode *N;
-  if (VTList.VTs[VTList.NumVTs - 1] != MVT::Glue) {
+  if (VTList.VTs[VTList.NumVTs-1] != MVT::Glue) {
     FoldingSetNodeID ID;
     AddNodeIDNode(ID, Opcode, VTList, Ops);
     void *IP = nullptr;
@@ -11637,32 +11557,32 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL,
 
 SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList,
                               SDValue N1) {
-  SDValue Ops[] = {N1};
+  SDValue Ops[] = { N1 };
   return getNode(Opcode, DL, VTList, Ops);
 }
 
 SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList,
                               SDValue N1, SDValue N2) {
-  SDValue Ops[] = {N1, N2};
+  SDValue Ops[] = { N1, N2 };
   return getNode(Opcode, DL, VTList, Ops);
 }
 
 SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList,
                               SDValue N1, SDValue N2, SDValue N3) {
-  SDValue Ops[] = {N1, N2, N3};
+  SDValue Ops[] = { N1, N2, N3 };
   return getNode(Opcode, DL, VTList, Ops);
 }
 
 SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList,
                               SDValue N1, SDValue N2, SDValue N3, SDValue N4) {
-  SDValue Ops[] = {N1, N2, N3, N4};
+  SDValue Ops[] = { N1, N2, N3, N4 };
   return getNode(Opcode, DL, VTList, Ops);
 }
 
 SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList,
                               SDValue N1, SDValue N2, SDValue N3, SDValue N4,
                               SDValue N5) {
-  SDValue Ops[] = {N1, N2, N3, N4, N5};
+  SDValue Ops[] = { N1, N2, N3, N4, N5 };
   return getNode(Opcode, DL, VTList, Ops);
 }
 
@@ -11752,6 +11672,7 @@ SDVTList SelectionDAG::getVTList(ArrayRef<EVT> VTs) {
   return Result->getSDVTList();
 }
 
+
 /// UpdateNodeOperands - *Mutate* the specified node in-place to have the
 /// specified operands.  If the resultant node already exists in the DAG,
 /// this does not modify the specified node, instead it returns the node that
@@ -11762,8 +11683,7 @@ SDNode *SelectionDAG::UpdateNodeOperands(SDNode *N, SDValue Op) {
   assert(N->getNumOperands() == 1 && "Update with wrong number of operands");
 
   // Check to see if there is no change.
-  if (Op == N->getOperand(0))
-    return N;
+  if (Op == N->getOperand(0)) return N;
 
   // See if the modified node already exists.
   void *InsertPos = nullptr;
@@ -11780,8 +11700,7 @@ SDNode *SelectionDAG::UpdateNodeOperands(SDNode *N, SDValue Op) {
 
   updateDivergence(N);
   // If this gets put into a CSE map, add it.
-  if (InsertPos)
-    CSEMap.InsertNode(N, InsertPos);
+  if (InsertPos) CSEMap.InsertNode(N, InsertPos);
   return N;
 }
 
@@ -11790,7 +11709,7 @@ SDNode *SelectionDAG::UpdateNodeOperands(SDNode *N, SDValue Op1, SDValue Op2) {
 
   // Check to see if there is no change.
   if (Op1 == N->getOperand(0) && Op2 == N->getOperand(1))
-    return N; // No operands changed, just return the input node.
+    return N;   // No operands changed, just return the input node.
 
   // See if the modified node already exists.
   void *InsertPos = nullptr;
@@ -11810,31 +11729,32 @@ SDNode *SelectionDAG::UpdateNodeOperands(SDNode *N, SDValue Op1, SDValue Op2) {
 
   updateDivergence(N);
   // If this gets put into a CSE map, add it.
-  if (InsertPos)
-    CSEMap.InsertNode(N, InsertPos);
+  if (InsertPos) CSEMap.InsertNode(N, InsertPos);
   return N;
 }
 
-SDNode *SelectionDAG::UpdateNodeOperands(SDNode *N, SDValue Op1, SDValue Op2,
-                                         SDValue Op3) {
-  SDValue Ops[] = {Op1, Op2, Op3};
+SDNode *SelectionDAG::
+UpdateNodeOperands(SDNode *N, SDValue Op1, SDValue Op2, SDValue Op3) {
+  SDValue Ops[] = { Op1, Op2, Op3 };
   return UpdateNodeOperands(N, Ops);
 }
 
-SDNode *SelectionDAG::UpdateNodeOperands(SDNode *N, SDValue Op1, SDValue Op2,
-                                         SDValue Op3, SDValue Op4) {
-  SDValue Ops[] = {Op1, Op2, Op3, Op4};
+SDNode *SelectionDAG::
+UpdateNodeOperands(SDNode *N, SDValue Op1, SDValue Op2,
+                   SDValue Op3, SDValue Op4) {
+  SDValue Ops[] = { Op1, Op2, Op3, Op4 };
   return UpdateNodeOperands(N, Ops);
 }
 
-SDNode *SelectionDAG::UpdateNodeOperands(SDNode *N, SDValue Op1, SDValue Op2,
-                                         SDValue Op3, SDValue Op4,
-                                         SDValue Op5) {
-  SDValue Ops[] = {Op1, Op2, Op3, Op4, Op5};
+SDNode *SelectionDAG::
+UpdateNodeOperands(SDNode *N, SDValue Op1, SDValue Op2,
+                   SDValue Op3, SDValue Op4, SDValue Op5) {
+  SDValue Ops[] = { Op1, Op2, Op3, Op4, Op5 };
   return UpdateNodeOperands(N, Ops);
 }
 
-SDNode *SelectionDAG::UpdateNodeOperands(SDNode *N, ArrayRef<SDValue> Ops) {
+SDNode *SelectionDAG::
+UpdateNodeOperands(SDNode *N, ArrayRef<SDValue> Ops) {
   unsigned NumOps = Ops.size();
   assert(N->getNumOperands() == NumOps &&
          "Update with wrong number of operands");
@@ -11860,8 +11780,7 @@ SDNode *SelectionDAG::UpdateNodeOperands(SDNode *N, ArrayRef<SDValue> Ops) {
 
   updateDivergence(N);
   // If this gets put into a CSE map, add it.
-  if (InsertPos)
-    CSEMap.InsertNode(N, InsertPos);
+  if (InsertPos) CSEMap.InsertNode(N, InsertPos);
   return N;
 }
 
@@ -11870,7 +11789,7 @@ SDNode *SelectionDAG::UpdateNodeOperands(SDNode *N, ArrayRef<SDValue> Ops) {
 void SDNode::DropOperands() {
   // Unlike the code in MorphNodeTo that does this, we don't need to
   // watch for dead nodes here.
-  for (op_iterator I = op_begin(), E = op_end(); I != E;) {
+  for (op_iterator I = op_begin(), E = op_end(); I != E; ) {
     SDUse &Use = *I++;
     Use.set(SDValue());
   }
@@ -11900,65 +11819,70 @@ void SelectionDAG::setNodeMemRefs(MachineSDNode *N,
 /// SelectNodeTo - These are wrappers around MorphNodeTo that accept a
 /// machine opcode.
 ///
-SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT) {
+SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc,
+                                   EVT VT) {
   SDVTList VTs = getVTList(VT);
   return SelectNodeTo(N, MachineOpc, VTs, {});
 }
 
-SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT,
-                                   SDValue Op1) {
+SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc,
+                                   EVT VT, SDValue Op1) {
   SDVTList VTs = getVTList(VT);
-  SDValue Ops[] = {Op1};
+  SDValue Ops[] = { Op1 };
   return SelectNodeTo(N, MachineOpc, VTs, Ops);
 }
 
-SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT,
-                                   SDValue Op1, SDValue Op2) {
+SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc,
+                                   EVT VT, SDValue Op1,
+                                   SDValue Op2) {
   SDVTList VTs = getVTList(VT);
-  SDValue Ops[] = {Op1, Op2};
+  SDValue Ops[] = { Op1, Op2 };
   return SelectNodeTo(N, MachineOpc, VTs, Ops);
 }
 
-SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT,
-                                   SDValue Op1, SDValue Op2, SDValue Op3) {
+SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc,
+                                   EVT VT, SDValue Op1,
+                                   SDValue Op2, SDValue Op3) {
   SDVTList VTs = getVTList(VT);
-  SDValue Ops[] = {Op1, Op2, Op3};
+  SDValue Ops[] = { Op1, Op2, Op3 };
   return SelectNodeTo(N, MachineOpc, VTs, Ops);
 }
 
-SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT,
-                                   ArrayRef<SDValue> Ops) {
+SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc,
+                                   EVT VT, ArrayRef<SDValue> Ops) {
   SDVTList VTs = getVTList(VT);
   return SelectNodeTo(N, MachineOpc, VTs, Ops);
 }
 
-SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT1,
-                                   EVT VT2, ArrayRef<SDValue> Ops) {
+SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc,
+                                   EVT VT1, EVT VT2, ArrayRef<SDValue> Ops) {
   SDVTList VTs = getVTList(VT1, VT2);
   return SelectNodeTo(N, MachineOpc, VTs, Ops);
 }
 
-SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT1,
-                                   EVT VT2) {
+SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc,
+                                   EVT VT1, EVT VT2) {
   SDVTList VTs = getVTList(VT1, VT2);
   return SelectNodeTo(N, MachineOpc, VTs, {});
 }
 
-SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT1,
-                                   EVT VT2, EVT VT3, ArrayRef<SDValue> Ops) {
+SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc,
+                                   EVT VT1, EVT VT2, EVT VT3,
+                                   ArrayRef<SDValue> Ops) {
   SDVTList VTs = getVTList(VT1, VT2, VT3);
   return SelectNodeTo(N, MachineOpc, VTs, Ops);
 }
 
-SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT1,
-                                   EVT VT2, SDValue Op1, SDValue Op2) {
+SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc,
+                                   EVT VT1, EVT VT2,
+                                   SDValue Op1, SDValue Op2) {
   SDVTList VTs = getVTList(VT1, VT2);
-  SDValue Ops[] = {Op1, Op2};
+  SDValue Ops[] = { Op1, Op2 };
   return SelectNodeTo(N, MachineOpc, VTs, Ops);
 }
 
-SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc, SDVTList VTs,
-                                   ArrayRef<SDValue> Ops) {
+SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc,
+                                   SDVTList VTs,ArrayRef<SDValue> Ops) {
   SDNode *New = MorphNodeTo(N, ~MachineOpc, VTs, Ops);
   // Reset the NodeID to -1.
   New->setNodeId(-1);
@@ -12002,11 +11926,11 @@ SDNode *SelectionDAG::UpdateSDLocOnMergeSDNode(SDNode *N, const SDLoc &OLoc) {
 /// As a consequence it isn't appropriate to use from within the DAG combiner or
 /// the legalizer which maintain worklists that would need to be updated when
 /// deleting things.
-SDNode *SelectionDAG::MorphNodeTo(SDNode *N, unsigned Opc, SDVTList VTs,
-                                  ArrayRef<SDValue> Ops) {
+SDNode *SelectionDAG::MorphNodeTo(SDNode *N, unsigned Opc,
+                                  SDVTList VTs, ArrayRef<SDValue> Ops) {
   // If an identical node already exists, use it.
   void *IP = nullptr;
-  if (VTs.VTs[VTs.NumVTs - 1] != MVT::Glue) {
+  if (VTs.VTs[VTs.NumVTs-1] != MVT::Glue) {
     FoldingSetNodeID ID;
     AddNodeIDNode(ID, Opc, VTs, Ops);
     if (SDNode *ON = FindNodeOrInsertPos(ID, SDLoc(N), IP))
@@ -12023,8 +11947,8 @@ SDNode *SelectionDAG::MorphNodeTo(SDNode *N, unsigned Opc, SDVTList VTs,
 
   // Clear the operands list, updating used nodes to remove this from their
   // use list.  Keep track of any operands that become dead as a result.
-  SmallPtrSet<SDNode *, 16> DeadNodeSet;
-  for (SDNode::op_iterator I = N->op_begin(), E = N->op_end(); I != E;) {
+  SmallPtrSet<SDNode*, 16> DeadNodeSet;
+  for (SDNode::op_iterator I = N->op_begin(), E = N->op_end(); I != E; ) {
     SDUse &Use = *I++;
     SDNode *Used = Use.getNode();
     Use.set(SDValue());
@@ -12051,24 +11975,20 @@ SDNode *SelectionDAG::MorphNodeTo(SDNode *N, unsigned Opc, SDVTList VTs,
   }
 
   if (IP)
-    CSEMap.InsertNode(N, IP); // Memoize the new node.
+    CSEMap.InsertNode(N, IP);   // Memoize the new node.
   return N;
 }
 
-SDNode *SelectionDAG::mutateStrictFPToFP(SDNode *Node) {
+SDNode* SelectionDAG::mutateStrictFPToFP(SDNode *Node) {
   unsigned OrigOpc = Node->getOpcode();
   unsigned NewOpc;
   switch (OrigOpc) {
   default:
     llvm_unreachable("mutateStrictFPToFP called with unexpected opcode!");
 #define DAG_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN)               \
-  case ISD::STRICT_##DAGN:                                                     \
-    NewOpc = ISD::DAGN;                                                        \
-    break;
+  case ISD::STRICT_##DAGN: NewOpc = ISD::DAGN; break;
 #define CMP_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN)               \
-  case ISD::STRICT_##DAGN:                                                     \
-    NewOpc = ISD::SETCC;                                                       \
-    break;
+  case ISD::STRICT_##DAGN: NewOpc = ISD::SETCC; break;
 #include "llvm/IR/ConstrainedOps.def"
   }
 
@@ -12116,14 +12036,14 @@ MachineSDNode *SelectionDAG::getMachineNode(unsigned Opcode, const SDLoc &dl,
 MachineSDNode *SelectionDAG::getMachineNode(unsigned Opcode, const SDLoc &dl,
                                             EVT VT, SDValue Op1) {
   SDVTList VTs = getVTList(VT);
-  SDValue Ops[] = {Op1};
+  SDValue Ops[] = { Op1 };
   return getMachineNode(Opcode, dl, VTs, Ops);
 }
 
 MachineSDNode *SelectionDAG::getMachineNode(unsigned Opcode, const SDLoc &dl,
                                             EVT VT, SDValue Op1, SDValue Op2) {
   SDVTList VTs = getVTList(VT);
-  SDValue Ops[] = {Op1, Op2};
+  SDValue Ops[] = { Op1, Op2 };
   return getMachineNode(Opcode, dl, VTs, Ops);
 }
 
@@ -12131,7 +12051,7 @@ MachineSDNode *SelectionDAG::getMachineNode(unsigned Opcode, const SDLoc &dl,
                                             EVT VT, SDValue Op1, SDValue Op2,
                                             SDValue Op3) {
   SDVTList VTs = getVTList(VT);
-  SDValue Ops[] = {Op1, Op2, Op3};
+  SDValue Ops[] = { Op1, Op2, Op3 };
   return getMachineNode(Opcode, dl, VTs, Ops);
 }
 
@@ -12145,7 +12065,7 @@ MachineSDNode *SelectionDAG::getMachineNode(unsigned Opcode, const SDLoc &dl,
                                             EVT VT1, EVT VT2, SDValue Op1,
                                             SDValue Op2) {
   SDVTList VTs = getVTList(VT1, VT2);
-  SDValue Ops[] = {Op1, Op2};
+  SDValue Ops[] = { Op1, Op2 };
   return getMachineNode(Opcode, dl, VTs, Ops);
 }
 
@@ -12153,7 +12073,7 @@ MachineSDNode *SelectionDAG::getMachineNode(unsigned Opcode, const SDLoc &dl,
                                             EVT VT1, EVT VT2, SDValue Op1,
                                             SDValue Op2, SDValue Op3) {
   SDVTList VTs = getVTList(VT1, VT2);
-  SDValue Ops[] = {Op1, Op2, Op3};
+  SDValue Ops[] = { Op1, Op2, Op3 };
   return getMachineNode(Opcode, dl, VTs, Ops);
 }
 
@@ -12168,7 +12088,7 @@ MachineSDNode *SelectionDAG::getMachineNode(unsigned Opcode, const SDLoc &dl,
                                             EVT VT1, EVT VT2, EVT VT3,
                                             SDValue Op1, SDValue Op2) {
   SDVTList VTs = getVTList(VT1, VT2, VT3);
-  SDValue Ops[] = {Op1, Op2};
+  SDValue Ops[] = { Op1, Op2 };
   return getMachineNode(Opcode, dl, VTs, Ops);
 }
 
@@ -12177,7 +12097,7 @@ MachineSDNode *SelectionDAG::getMachineNode(unsigned Opcode, const SDLoc &dl,
                                             SDValue Op1, SDValue Op2,
                                             SDValue Op3) {
   SDVTList VTs = getVTList(VT1, VT2, VT3);
-  SDValue Ops[] = {Op1, Op2, Op3};
+  SDValue Ops[] = { Op1, Op2, Op3 };
   return getMachineNode(Opcode, dl, VTs, Ops);
 }
 
@@ -12198,7 +12118,7 @@ MachineSDNode *SelectionDAG::getMachineNode(unsigned Opcode, const SDLoc &dl,
 MachineSDNode *SelectionDAG::getMachineNode(unsigned Opcode, const SDLoc &DL,
                                             SDVTList VTs,
                                             ArrayRef<SDValue> Ops) {
-  bool DoCSE = VTs.VTs[VTs.NumVTs - 1] != MVT::Glue;
+  bool DoCSE = VTs.VTs[VTs.NumVTs-1] != MVT::Glue;
   MachineSDNode *N;
   void *IP = nullptr;
 
@@ -12228,8 +12148,8 @@ MachineSDNode *SelectionDAG::getMachineNode(unsigned Opcode, const SDLoc &DL,
 SDValue SelectionDAG::getTargetExtractSubreg(int SRIdx, const SDLoc &DL, EVT VT,
                                              SDValue Operand) {
   SDValue SRIdxVal = getTargetConstant(SRIdx, DL, MVT::i32);
-  SDNode *Subreg =
-      getMachineNode(TargetOpcode::EXTRACT_SUBREG, DL, VT, Operand, SRIdxVal);
+  SDNode *Subreg = getMachineNode(TargetOpcode::EXTRACT_SUBREG, DL,
+                                  VT, Operand, SRIdxVal);
   return SDValue(Subreg, 0);
 }
 
@@ -12238,8 +12158,8 @@ SDValue SelectionDAG::getTargetExtractSubreg(int SRIdx, const SDLoc &DL, EVT VT,
 SDValue SelectionDAG::getTargetInsertSubreg(int SRIdx, const SDLoc &DL, EVT VT,
                                             SDValue Operand, SDValue Subreg) {
   SDValue SRIdxVal = getTargetConstant(SRIdx, DL, MVT::i32);
-  SDNode *Result = getMachineNode(TargetOpcode::INSERT_SUBREG, DL, VT, Operand,
-                                  Subreg, SRIdxVal);
+  SDNode *Result = getMachineNode(TargetOpcode::INSERT_SUBREG, DL,
+                                  VT, Operand, Subreg, SRIdxVal);
   return SDValue(Result, 0);
 }
 
@@ -12587,8 +12507,8 @@ void SelectionDAG::salvageDebugInfo(SDNode &N) {
 }
 
 /// Creates a SDDbgLabel node.
-SDDbgLabel *SelectionDAG::getDbgLabel(DILabel *Label, const DebugLoc &DL,
-                                      unsigned O) {
+SDDbgLabel *SelectionDAG::getDbgLabel(DILabel *Label,
+                                      const DebugLoc &DL, unsigned O) {
   assert(cast<DILabel>(Label)->isValidLocationForIntrinsic(DL) &&
          "Expected inlined-at fields to agree");
   return new (DbgInfo->getAlloc()) SDDbgLabel(Label, DL, O);
@@ -12611,9 +12531,10 @@ class RAUWUpdateListener : public SelectionDAG::DAGUpdateListener {
   }
 
 public:
-  RAUWUpdateListener(SelectionDAG &d, SDNode::use_iterator &ui,
+  RAUWUpdateListener(SelectionDAG &d,
+                     SDNode::use_iterator &ui,
                      SDNode::use_iterator &ue)
-      : SelectionDAG::DAGUpdateListener(d), UI(ui), UE(ue) {}
+    : SelectionDAG::DAGUpdateListener(d), UI(ui), UE(ue) {}
 };
 
 } // end anonymous namespace
@@ -12735,7 +12656,7 @@ void SelectionDAG::ReplaceAllUsesWith(SDNode *From, SDNode *To) {
 /// This version can replace From with any result values.  To must match the
 /// number and types of values returned by From.
 void SelectionDAG::ReplaceAllUsesWith(SDNode *From, const SDValue *To) {
-  if (From->getNumValues() == 1) // Handle the simple case efficiently.
+  if (From->getNumValues() == 1)  // Handle the simple case efficiently.
     return ReplaceAllUsesWith(SDValue(From, 0), To[0]);
 
   for (unsigned i = 0, e = From->getNumValues(); i != e; ++i) {
@@ -12785,10 +12706,9 @@ void SelectionDAG::ReplaceAllUsesWith(SDNode *From, const SDValue *To) {
 /// ReplaceAllUsesOfValueWith - Replace any uses of From with To, leaving
 /// uses of other values produced by From.getNode() alone.  The Deleted
 /// vector is handled the same way as for ReplaceAllUsesWith.
-void SelectionDAG::ReplaceAllUsesOfValueWith(SDValue From, SDValue To) {
+void SelectionDAG::ReplaceAllUsesOfValueWith(SDValue From, SDValue To){
   // Handle the really simple, really trivial case efficiently.
-  if (From == To)
-    return;
+  if (From == To) return;
 
   // Handle the simple, trivial, case efficiently.
   if (From.getNode()->getNumValues() == 1) {
@@ -12962,7 +12882,8 @@ void SelectionDAG::VerifyDAGDivergence() {
 /// may appear in both the From and To list.  The Deleted vector is
 /// handled the same way as for ReplaceAllUsesWith.
 void SelectionDAG::ReplaceAllUsesOfValuesWith(const SDValue *From,
-                                              const SDValue *To, unsigned Num) {
+                                              const SDValue *To,
+                                              unsigned Num){
   // Handle the simple, trivial case efficiently.
   if (Num == 1)
     return ReplaceAllUsesOfValueWith(*From, *To);
@@ -12990,7 +12911,7 @@ void SelectionDAG::ReplaceAllUsesOfValuesWith(const SDValue *From,
   RAUOVWUpdateListener Listener(*this, Uses);
 
   for (unsigned UseIndex = 0, UseIndexEnd = Uses.size();
-       UseIndex != UseIndexEnd;) {
+       UseIndex != UseIndexEnd; ) {
     // We know that this user uses some value of From.  If it is the right
     // value, update it.
     SDNode *User = Uses[UseIndex].User;
@@ -13085,8 +13006,7 @@ unsigned SelectionDAG::AssignTopologicalOrder() {
       allnodes_iterator I(N);
       SDNode *S = &*++I;
       dbgs() << "Overran sorted position:\n";
-      S->dumprFull(this);
-      dbgs() << "\n";
+      S->dumprFull(this); dbgs() << "\n";
       dbgs() << "Checking if this is due to cycles\n";
       checkForCycles(this, true);
 #endif
@@ -13094,14 +13014,15 @@ unsigned SelectionDAG::AssignTopologicalOrder() {
     }
   }
 
-  assert(SortedPos == AllNodes.end() && "Topological sort incomplete!");
+  assert(SortedPos == AllNodes.end() &&
+         "Topological sort incomplete!");
   assert(AllNodes.front().getOpcode() == ISD::EntryToken &&
          "First node in topological sort is not the entry token!");
   assert(AllNodes.front().getNodeId() == 0 &&
          "First node in topological sort has non-zero id!");
   assert(AllNodes.front().getNumOperands() == 0 &&
          "First node in topological sort has operands!");
-  assert(AllNodes.back().getNodeId() == (int)DAGSize - 1 &&
+  assert(AllNodes.back().getNodeId() == (int)DAGSize-1 &&
          "Last node in topologic sort has unexpected id!");
   assert(AllNodes.back().use_empty() &&
          "Last node in topologic sort has users!");
@@ -13199,11 +13120,10 @@ SDValue SelectionDAG::getSymbolFunctionGlobalAddress(SDValue Op,
   auto *Function = Module->getFunction(Symbol);
 
   if (OutFunction != nullptr)
-    *OutFunction = Function;
+      *OutFunction = Function;
 
   if (Function != nullptr) {
-    auto PtrTy =
-        TLI->getPointerTy(getDataLayout(), Function->getAddressSpace());
+    auto PtrTy = TLI->getPointerTy(getDataLayout(), Function->getAddressSpace());
     return getGlobalAddress(Function, SDLoc(Op), PtrTy);
   }
 
@@ -13295,9 +13215,11 @@ bool llvm::isNeutralConstant(unsigned Opcode, SDNodeFlags Flags, SDValue V,
       // Neutral element for fminnum is NaN, Inf or FLT_MAX, depending on FMF.
       EVT VT = V.getValueType();
       const fltSemantics &Semantics = VT.getFltSemantics();
-      APFloat NeutralAF = !Flags.hasNoNaNs()   ? APFloat::getQNaN(Semantics)
-                          : !Flags.hasNoInfs() ? APFloat::getInf(Semantics)
-                                               : APFloat::getLargest(Semantics);
+      APFloat NeutralAF = !Flags.hasNoNaNs()
+                              ? APFloat::getQNaN(Semantics)
+                              : !Flags.hasNoInfs()
+                                    ? APFloat::getInf(Semantics)
+                                    : APFloat::getLargest(Semantics);
       if (Opcode == ISD::FMAXNUM)
         NeutralAF.changeSign();
 
@@ -13477,7 +13399,9 @@ bool llvm::isZeroOrZeroSplatFP(SDValue N, bool AllowUndefs) {
   return C && C->isZero();
 }
 
-HandleSDNode::~HandleSDNode() { DropOperands(); }
+HandleSDNode::~HandleSDNode() {
+  DropOperands();
+}
 
 MemSDNode::MemSDNode(
     unsigned Opc, unsigned Order, const DebugLoc &dl, SDVTList VTs, EVT memvt,
@@ -13510,19 +13434,21 @@ MemSDNode::MemSDNode(
 
 /// Profile - Gather unique data for the node.
 ///
-void SDNode::Profile(FoldingSetNodeID &ID) const { AddNodeIDNode(ID, this); }
+void SDNode::Profile(FoldingSetNodeID &ID) const {
+  AddNodeIDNode(ID, this);
+}
 
 namespace {
 
-struct EVTArray {
-  std::vector<EVT> VTs;
+  struct EVTArray {
+    std::vector<EVT> VTs;
 
-  EVTArray() {
-    VTs.reserve(MVT::VALUETYPE_SIZE);
-    for (unsigned i = 0; i < MVT::VALUETYPE_SIZE; ++i)
-      VTs.push_back(MVT((MVT::SimpleValueType)i));
-  }
-};
+    EVTArray() {
+      VTs.reserve(MVT::VALUETYPE_SIZE);
+      for (unsigned i = 0; i < MVT::VALUETYPE_SIZE; ++i)
+        VTs.push_back(MVT((MVT::SimpleValueType)i));
+    }
+  };
 
 } // end anonymous namespace
 
@@ -13595,13 +13521,11 @@ bool SDNode::isOperandOf(const SDNode *N) const {
 /// constraint is necessary to allow transformations like splitting loads.
 bool SDValue::reachesChainWithoutSideEffects(SDValue Dest,
                                              unsigned Depth) const {
-  if (*this == Dest)
-    return true;
+  if (*this == Dest) return true;
 
   // Don't search too deeply, we just want to be able to see through
   // TokenFactor's etc.
-  if (Depth == 0)
-    return false;
+  if (Depth == 0) return false;
 
   // If this is a token factor, all inputs to the TF happen in parallel.
   if (getOpcode() == ISD::TokenFactor) {
@@ -13628,7 +13552,7 @@ bool SDValue::reachesChainWithoutSideEffects(SDValue Dest,
   // Loads don't have side effects, look through them.
   if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(*this)) {
     if (Ld->isUnordered())
-      return Ld->getChain().reachesChainWithoutSideEffects(Dest, Depth - 1);
+      return Ld->getChain().reachesChainWithoutSideEffects(Dest, Depth-1);
   }
   return false;
 }
@@ -13814,7 +13738,7 @@ SDValue SelectionDAG::UnrollVectorOp(SDNode *N, unsigned ResNE) {
   SmallVector<SDValue, 4> Operands(N->getNumOperands());
 
   unsigned i;
-  for (i = 0; i != NE; ++i) {
+  for (i= 0; i != NE; ++i) {
     for (unsigned j = 0, e = N->getNumOperands(); j != e; ++j) {
       SDValue Operand = N->getOperand(j);
       EVT OperandVT = Operand.getValueType();
@@ -13830,8 +13754,8 @@ SDValue SelectionDAG::UnrollVectorOp(SDNode *N, unsigned ResNE) {
 
     switch (N->getOpcode()) {
     default: {
-      Scalars.push_back(
-          getNode(N->getOpcode(), dl, EltVT, Operands, N->getFlags()));
+      Scalars.push_back(getNode(N->getOpcode(), dl, EltVT, Operands,
+                                N->getFlags()));
       break;
     }
     case ISD::VSELECT:
@@ -13842,14 +13766,15 @@ SDValue SelectionDAG::UnrollVectorOp(SDNode *N, unsigned ResNE) {
     case ISD::SRL:
     case ISD::ROTL:
     case ISD::ROTR:
-      Scalars.push_back(getNode(
-          N->getOpcode(), dl, EltVT, Operands[0],
-          getShiftAmountOperand(Operands[0].getValueType(), Operands[1])));
+      Scalars.push_back(getNode(N->getOpcode(), dl, EltVT, Operands[0],
+                               getShiftAmountOperand(Operands[0].getValueType(),
+                                                     Operands[1])));
       break;
     case ISD::SIGN_EXTEND_INREG: {
       EVT ExtVT = cast<VTSDNode>(Operands[1])->getVT().getVectorElementType();
-      Scalars.push_back(
-          getNode(N->getOpcode(), dl, EltVT, Operands[0], getValueType(ExtVT)));
+      Scalars.push_back(getNode(N->getOpcode(), dl, EltVT,
+                                Operands[0],
+                                getValueType(ExtVT)));
       break;
     }
     case ISD::ADDRSPACECAST: {
@@ -13869,8 +13794,8 @@ SDValue SelectionDAG::UnrollVectorOp(SDNode *N, unsigned ResNE) {
   return getBuildVector(VecVT, dl, Scalars);
 }
 
-std::pair<SDValue, SDValue>
-SelectionDAG::UnrollVectorOverflowOp(SDNode *N, unsigned ResNE) {
+std::pair<SDValue, SDValue> SelectionDAG::UnrollVectorOverflowOp(
+    SDNode *N, unsigned ResNE) {
   unsigned Opcode = N->getOpcode();
   assert((Opcode == ISD::UADDO || Opcode == ISD::SADDO ||
           Opcode == ISD::USUBO || Opcode == ISD::SSUBO ||
@@ -13901,9 +13826,10 @@ SelectionDAG::UnrollVectorOverflowOp(SDNode *N, unsigned ResNE) {
   SmallVector<SDValue, 8> OvScalars;
   for (unsigned i = 0; i < NE; ++i) {
     SDValue Res = getNode(Opcode, dl, VTs, LHSScalars[i], RHSScalars[i]);
-    SDValue Ov = getSelect(dl, OvEltVT, Res.getValue(1),
-                           getBoolConstant(true, dl, OvEltVT, ResVT),
-                           getConstant(0, dl, OvEltVT));
+    SDValue Ov =
+        getSelect(dl, OvEltVT, Res.getValue(1),
+                  getBoolConstant(true, dl, OvEltVT, ResVT),
+                  getConstant(0, dl, OvEltVT));
 
     ResScalars.push_back(Res);
     OvScalars.push_back(Ov);
@@ -14041,10 +13967,9 @@ SelectionDAG::GetDependentSplitDestVTs(const EVT &VT, const EVT &EnvVT,
 
 /// SplitVector - Split the vector with EXTRACT_SUBVECTOR and return the
 /// low/high part.
-std::pair<SDValue, SDValue> SelectionDAG::SplitVector(const SDValue &N,
-                                                      const SDLoc &DL,
-                                                      const EVT &LoVT,
-                                                      const EVT &HiVT) {
+std::pair<SDValue, SDValue>
+SelectionDAG::SplitVector(const SDValue &N, const SDLoc &DL, const EVT &LoVT,
+                          const EVT &HiVT) {
   assert(LoVT.isScalableVector() == HiVT.isScalableVector() &&
          LoVT.isScalableVector() == N.getValueType().isScalableVector() &&
          "Splitting vector with an invalid mixture of fixed and scalable "
@@ -14367,7 +14292,8 @@ void BuildVectorSDNode::recastRawBits(bool IsLittleEndian,
   unsigned SrcEltSizeInBits = SrcBitElements[0].getBitWidth();
   assert(((NumSrcOps * SrcEltSizeInBits) % DstEltSizeInBits) == 0 &&
          "Invalid bitcast scale");
-  assert(NumSrcOps == SrcUndefElements.size() && "Vector size mismatch");
+  assert(NumSrcOps == SrcUndefElements.size() &&
+         "Vector size mismatch");
 
   unsigned NumDstOps = (NumSrcOps * SrcEltSizeInBits) / DstEltSizeInBits;
   DstUndefElements.clear();
@@ -14515,7 +14441,8 @@ bool SelectionDAG::isConstantIntBuildVectorOrConstantInt(
   // Treat a GlobalAddress supporting constant offset folding as a
   // constant integer.
   if (auto *GA = dyn_cast<GlobalAddressSDNode>(N))
-    if (GA->getOpcode() == ISD::GlobalAddress && TLI->isOffsetFoldingLegal(GA))
+    if (GA->getOpcode() == ISD::GlobalAddress &&
+        TLI->isOffsetFoldingLegal(GA))
       return true;
 
   if ((N.getOpcode() == ISD::SPLAT_VECTOR) &&
@@ -14637,9 +14564,9 @@ SDValue SelectionDAG::getNeutralElement(unsigned Opcode, const SDLoc &DL,
   case ISD::FMAXNUM: {
     // Neutral element for fminnum is NaN, Inf or FLT_MAX, depending on FMF.
     const fltSemantics &Semantics = VT.getFltSemantics();
-    APFloat NeutralAF = !Flags.hasNoNaNs()   ? APFloat::getQNaN(Semantics)
-                        : !Flags.hasNoInfs() ? APFloat::getInf(Semantics)
-                                             : APFloat::getLargest(Semantics);
+    APFloat NeutralAF = !Flags.hasNoNaNs() ? APFloat::getQNaN(Semantics) :
+                        !Flags.hasNoInfs() ? APFloat::getInf(Semantics) :
+                        APFloat::getLargest(Semantics);
     if (Opcode == ISD::FMAXNUM)
       NeutralAF.changeSign();
 
@@ -14656,6 +14583,7 @@ SDValue SelectionDAG::getNeutralElement(unsigned Opcode, const SDLoc &DL,
 
     return getConstantFP(NeutralAF, DL, VT);
   }
+
   }
 }
 
@@ -14795,8 +14723,8 @@ void SelectionDAG::copyExtraInfo(SDNode *From, SDNode *To) {
 
 #ifndef NDEBUG
 static void checkForCyclesHelper(const SDNode *N,
-                                 SmallPtrSetImpl<const SDNode *> &Visited,
-                                 SmallPtrSetImpl<const SDNode *> &Checked,
+                                 SmallPtrSetImpl<const SDNode*> &Visited,
+                                 SmallPtrSetImpl<const SDNode*> &Checked,
                                  const llvm::SelectionDAG *DAG) {
   // If this node has already been checked, don't check it again.
   if (Checked.count(N))
@@ -14807,8 +14735,7 @@ static void checkForCyclesHelper(const SDNode *N,
   if (!Visited.insert(N).second) {
     errs() << "Detected cycle in SelectionDAG\n";
     dbgs() << "Offending node:\n";
-    N->dumprFull(DAG);
-    dbgs() << "\n";
+    N->dumprFull(DAG); dbgs() << "\n";
     abort();
   }
 
@@ -14820,20 +14747,21 @@ static void checkForCyclesHelper(const SDNode *N,
 }
 #endif
 
-void llvm::checkForCycles(const llvm::SDNode *N, const llvm::SelectionDAG *DAG,
+void llvm::checkForCycles(const llvm::SDNode *N,
+                          const llvm::SelectionDAG *DAG,
                           bool force) {
 #ifndef NDEBUG
   bool check = force;
 #ifdef EXPENSIVE_CHECKS
   check = true;
-#endif // EXPENSIVE_CHECKS
+#endif  // EXPENSIVE_CHECKS
   if (check) {
     assert(N && "Checking nonexistent SDNode");
-    SmallPtrSet<const SDNode *, 32> visited;
-    SmallPtrSet<const SDNode *, 32> checked;
+    SmallPtrSet<const SDNode*, 32> visited;
+    SmallPtrSet<const SDNode*, 32> checked;
     checkForCyclesHelper(N, visited, checked, DAG);
   }
-#endif // !NDEBUG
+#endif  // !NDEBUG
 }
 
 void llvm::checkForCycles(const llvm::SelectionDAG *DAG, bool force) {

>From 8225417b3880baa30b66ffb5ba33098c81c3f5a2 Mon Sep 17 00:00:00 2001
From: Ayokunle Amodu <ayokunle321 at gmail.com>
Date: Tue, 3 Mar 2026 10:20:47 -0700
Subject: [PATCH 5/7] add vec tests

---
 llvm/test/CodeGen/X86/known-never-zero.ll | 146 ++++++++++++++++++++++
 1 file changed, 146 insertions(+)

diff --git a/llvm/test/CodeGen/X86/known-never-zero.ll b/llvm/test/CodeGen/X86/known-never-zero.ll
index 157bd76b5cdb3..30f45667df580 100644
--- a/llvm/test/CodeGen/X86/known-never-zero.ll
+++ b/llvm/test/CodeGen/X86/known-never-zero.ll
@@ -954,6 +954,79 @@ define i32 @udiv_known_nonzero(i32 %xx, i32 %y) {
   ret i32 %r
 }
 
+define i32 @udiv_known_nonzero_vec(<4 x i32> %xx, <4 x i32> %y, ptr %p) nounwind {
+; X86-LABEL: udiv_known_nonzero_vec:
+; X86:       # %bb.0:
+; X86-NEXT:    pushl %esi
+; X86-NEXT:    movl {{[0-9]+}}(%esp), %ecx
+; X86-NEXT:    por {{\.?LCPI[0-9]+_[0-9]+}}, %xmm0
+; X86-NEXT:    pshufd {{.*#+}} xmm2 = xmm1[3,3,3,3]
+; X86-NEXT:    movd %xmm2, %esi
+; X86-NEXT:    movl $-1, %eax
+; X86-NEXT:    xorl %edx, %edx
+; X86-NEXT:    divl %esi
+; X86-NEXT:    movd %eax, %xmm3
+; X86-NEXT:    pshufd {{.*#+}} xmm2 = xmm1[2,3,2,3]
+; X86-NEXT:    movd %xmm2, %esi
+; X86-NEXT:    movl $-1, %eax
+; X86-NEXT:    xorl %edx, %edx
+; X86-NEXT:    divl %esi
+; X86-NEXT:    movd %eax, %xmm2
+; X86-NEXT:    punpckldq {{.*#+}} xmm2 = xmm2[0],xmm3[0],xmm2[1],xmm3[1]
+; X86-NEXT:    pshufd {{.*#+}} xmm3 = xmm1[1,1,1,1]
+; X86-NEXT:    movd %xmm3, %esi
+; X86-NEXT:    movl $-1, %eax
+; X86-NEXT:    xorl %edx, %edx
+; X86-NEXT:    divl %esi
+; X86-NEXT:    movd %eax, %xmm3
+; X86-NEXT:    movd %xmm1, %esi
+; X86-NEXT:    movd %xmm0, %eax
+; X86-NEXT:    xorl %edx, %edx
+; X86-NEXT:    divl %esi
+; X86-NEXT:    movd %eax, %xmm0
+; X86-NEXT:    punpckldq {{.*#+}} xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
+; X86-NEXT:    punpcklqdq {{.*#+}} xmm0 = xmm0[0],xmm2[0]
+; X86-NEXT:    movdqa %xmm0, (%ecx)
+; X86-NEXT:    rep bsfl %eax, %eax
+; X86-NEXT:    popl %esi
+; X86-NEXT:    retl
+;
+; X64-LABEL: udiv_known_nonzero_vec:
+; X64:       # %bb.0:
+; X64-NEXT:    vpor {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0, %xmm0
+; X64-NEXT:    vpextrd $1, %xmm1, %ecx
+; X64-NEXT:    vpextrd $1, %xmm0, %eax
+; X64-NEXT:    xorl %edx, %edx
+; X64-NEXT:    divl %ecx
+; X64-NEXT:    movl %eax, %ecx
+; X64-NEXT:    vmovd %xmm1, %esi
+; X64-NEXT:    vmovd %xmm0, %eax
+; X64-NEXT:    xorl %edx, %edx
+; X64-NEXT:    divl %esi
+; X64-NEXT:    vmovd %eax, %xmm2
+; X64-NEXT:    vpinsrd $1, %ecx, %xmm2, %xmm2
+; X64-NEXT:    vpextrd $2, %xmm1, %ecx
+; X64-NEXT:    vpextrd $2, %xmm0, %eax
+; X64-NEXT:    xorl %edx, %edx
+; X64-NEXT:    divl %ecx
+; X64-NEXT:    vpinsrd $2, %eax, %xmm2, %xmm2
+; X64-NEXT:    vpextrd $3, %xmm1, %ecx
+; X64-NEXT:    vpextrd $3, %xmm0, %eax
+; X64-NEXT:    xorl %edx, %edx
+; X64-NEXT:    divl %ecx
+; X64-NEXT:    vpinsrd $3, %eax, %xmm2, %xmm0
+; X64-NEXT:    vmovdqa %xmm0, (%rdi)
+; X64-NEXT:    vmovd %xmm0, %eax
+; X64-NEXT:    rep bsfl %eax, %eax
+; X64-NEXT:    retq
+  %x = or <4 x i32> %xx, <i32 64, i32 -1, i32 -1, i32 -1>
+  %z = udiv exact <4 x i32> %x, %y
+  store <4 x i32> %z, ptr %p
+  %e = extractelement <4 x i32> %z, i32 0
+  %r = call i32 @llvm.cttz.i32(i32 %e, i1 false)
+  ret i32 %r
+}
+
 define i32 @udiv_maybe_zero(i32 %x, i32 %y) {
 ; X86-LABEL: udiv_maybe_zero:
 ; X86:       # %bb.0:
@@ -1003,6 +1076,79 @@ define i32 @sdiv_known_nonzero(i32 %xx, i32 %y) {
   ret i32 %r
 }
 
+define i32 @sdiv_known_nonzero_vec(<4 x i32> %xx, <4 x i32> %y, ptr %p) nounwind {
+; X86-LABEL: sdiv_known_nonzero_vec:
+; X86:       # %bb.0:
+; X86-NEXT:    pushl %esi
+; X86-NEXT:    movl {{[0-9]+}}(%esp), %ecx
+; X86-NEXT:    por {{\.?LCPI[0-9]+_[0-9]+}}, %xmm0
+; X86-NEXT:    pshufd {{.*#+}} xmm2 = xmm1[3,3,3,3]
+; X86-NEXT:    movd %xmm2, %esi
+; X86-NEXT:    movl $-1, %eax
+; X86-NEXT:    cltd
+; X86-NEXT:    idivl %esi
+; X86-NEXT:    movd %eax, %xmm3
+; X86-NEXT:    pshufd {{.*#+}} xmm2 = xmm1[2,3,2,3]
+; X86-NEXT:    movd %xmm2, %esi
+; X86-NEXT:    movl $-1, %eax
+; X86-NEXT:    cltd
+; X86-NEXT:    idivl %esi
+; X86-NEXT:    movd %eax, %xmm2
+; X86-NEXT:    punpckldq {{.*#+}} xmm2 = xmm2[0],xmm3[0],xmm2[1],xmm3[1]
+; X86-NEXT:    pshufd {{.*#+}} xmm3 = xmm1[1,1,1,1]
+; X86-NEXT:    movd %xmm3, %esi
+; X86-NEXT:    movl $-1, %eax
+; X86-NEXT:    cltd
+; X86-NEXT:    idivl %esi
+; X86-NEXT:    movd %eax, %xmm3
+; X86-NEXT:    movd %xmm1, %esi
+; X86-NEXT:    movd %xmm0, %eax
+; X86-NEXT:    cltd
+; X86-NEXT:    idivl %esi
+; X86-NEXT:    movd %eax, %xmm0
+; X86-NEXT:    punpckldq {{.*#+}} xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
+; X86-NEXT:    punpcklqdq {{.*#+}} xmm0 = xmm0[0],xmm2[0]
+; X86-NEXT:    movdqa %xmm0, (%ecx)
+; X86-NEXT:    rep bsfl %eax, %eax
+; X86-NEXT:    popl %esi
+; X86-NEXT:    retl
+;
+; X64-LABEL: sdiv_known_nonzero_vec:
+; X64:       # %bb.0:
+; X64-NEXT:    vpor {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0, %xmm0
+; X64-NEXT:    vpextrd $1, %xmm1, %ecx
+; X64-NEXT:    vpextrd $1, %xmm0, %eax
+; X64-NEXT:    cltd
+; X64-NEXT:    idivl %ecx
+; X64-NEXT:    movl %eax, %ecx
+; X64-NEXT:    vmovd %xmm1, %esi
+; X64-NEXT:    vmovd %xmm0, %eax
+; X64-NEXT:    cltd
+; X64-NEXT:    idivl %esi
+; X64-NEXT:    vmovd %eax, %xmm2
+; X64-NEXT:    vpinsrd $1, %ecx, %xmm2, %xmm2
+; X64-NEXT:    vpextrd $2, %xmm1, %ecx
+; X64-NEXT:    vpextrd $2, %xmm0, %eax
+; X64-NEXT:    cltd
+; X64-NEXT:    idivl %ecx
+; X64-NEXT:    vpinsrd $2, %eax, %xmm2, %xmm2
+; X64-NEXT:    vpextrd $3, %xmm1, %ecx
+; X64-NEXT:    vpextrd $3, %xmm0, %eax
+; X64-NEXT:    cltd
+; X64-NEXT:    idivl %ecx
+; X64-NEXT:    vpinsrd $3, %eax, %xmm2, %xmm0
+; X64-NEXT:    vmovdqa %xmm0, (%rdi)
+; X64-NEXT:    vmovd %xmm0, %eax
+; X64-NEXT:    rep bsfl %eax, %eax
+; X64-NEXT:    retq
+  %x = or <4 x i32> %xx, <i32 64, i32 -1, i32 -1, i32 -1>
+  %z = sdiv exact <4 x i32> %x, %y
+  store <4 x i32> %z, ptr %p
+  %e = extractelement <4 x i32> %z, i32 0
+  %r = call i32 @llvm.cttz.i32(i32 %e, i1 false)
+  ret i32 %r
+}
+
 define i32 @sdiv_maybe_zero(i32 %x, i32 %y) {
 ; X86-LABEL: sdiv_maybe_zero:
 ; X86:       # %bb.0:

>From 104304436112f6d62fb40911ee449881a0aeca8d Mon Sep 17 00:00:00 2001
From: Ayokunle Amodu <ayokunle321 at gmail.com>
Date: Tue, 3 Mar 2026 10:25:55 -0700
Subject: [PATCH 6/7] update test with demandedelts handling and remove unit
 test

---
 llvm/test/CodeGen/X86/known-never-zero.ll     | 18 ++--
 .../AArch64/AArch64SelectionDAGTest.cpp       | 93 -------------------
 2 files changed, 12 insertions(+), 99 deletions(-)

diff --git a/llvm/test/CodeGen/X86/known-never-zero.ll b/llvm/test/CodeGen/X86/known-never-zero.ll
index 30f45667df580..cbc69f4eae7ae 100644
--- a/llvm/test/CodeGen/X86/known-never-zero.ll
+++ b/llvm/test/CodeGen/X86/known-never-zero.ll
@@ -987,7 +987,9 @@ define i32 @udiv_known_nonzero_vec(<4 x i32> %xx, <4 x i32> %y, ptr %p) nounwind
 ; X86-NEXT:    punpckldq {{.*#+}} xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
 ; X86-NEXT:    punpcklqdq {{.*#+}} xmm0 = xmm0[0],xmm2[0]
 ; X86-NEXT:    movdqa %xmm0, (%ecx)
-; X86-NEXT:    rep bsfl %eax, %eax
+; X86-NEXT:    bsfl %eax, %ecx
+; X86-NEXT:    movl $32, %eax
+; X86-NEXT:    cmovnel %ecx, %eax
 ; X86-NEXT:    popl %esi
 ; X86-NEXT:    retl
 ;
@@ -1016,8 +1018,9 @@ define i32 @udiv_known_nonzero_vec(<4 x i32> %xx, <4 x i32> %y, ptr %p) nounwind
 ; X64-NEXT:    divl %ecx
 ; X64-NEXT:    vpinsrd $3, %eax, %xmm2, %xmm0
 ; X64-NEXT:    vmovdqa %xmm0, (%rdi)
-; X64-NEXT:    vmovd %xmm0, %eax
-; X64-NEXT:    rep bsfl %eax, %eax
+; X64-NEXT:    vmovd %xmm0, %ecx
+; X64-NEXT:    movl $32, %eax
+; X64-NEXT:    rep bsfl %ecx, %eax
 ; X64-NEXT:    retq
   %x = or <4 x i32> %xx, <i32 64, i32 -1, i32 -1, i32 -1>
   %z = udiv exact <4 x i32> %x, %y
@@ -1109,7 +1112,9 @@ define i32 @sdiv_known_nonzero_vec(<4 x i32> %xx, <4 x i32> %y, ptr %p) nounwind
 ; X86-NEXT:    punpckldq {{.*#+}} xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
 ; X86-NEXT:    punpcklqdq {{.*#+}} xmm0 = xmm0[0],xmm2[0]
 ; X86-NEXT:    movdqa %xmm0, (%ecx)
-; X86-NEXT:    rep bsfl %eax, %eax
+; X86-NEXT:    bsfl %eax, %ecx
+; X86-NEXT:    movl $32, %eax
+; X86-NEXT:    cmovnel %ecx, %eax
 ; X86-NEXT:    popl %esi
 ; X86-NEXT:    retl
 ;
@@ -1138,8 +1143,9 @@ define i32 @sdiv_known_nonzero_vec(<4 x i32> %xx, <4 x i32> %y, ptr %p) nounwind
 ; X64-NEXT:    idivl %ecx
 ; X64-NEXT:    vpinsrd $3, %eax, %xmm2, %xmm0
 ; X64-NEXT:    vmovdqa %xmm0, (%rdi)
-; X64-NEXT:    vmovd %xmm0, %eax
-; X64-NEXT:    rep bsfl %eax, %eax
+; X64-NEXT:    vmovd %xmm0, %ecx
+; X64-NEXT:    movl $32, %eax
+; X64-NEXT:    rep bsfl %ecx, %eax
 ; X64-NEXT:    retq
   %x = or <4 x i32> %xx, <i32 64, i32 -1, i32 -1, i32 -1>
   %z = sdiv exact <4 x i32> %x, %y
diff --git a/llvm/unittests/Target/AArch64/AArch64SelectionDAGTest.cpp b/llvm/unittests/Target/AArch64/AArch64SelectionDAGTest.cpp
index 09e604808db83..b0c48e8c97995 100644
--- a/llvm/unittests/Target/AArch64/AArch64SelectionDAGTest.cpp
+++ b/llvm/unittests/Target/AArch64/AArch64SelectionDAGTest.cpp
@@ -1574,97 +1574,4 @@ TEST_F(AArch64SelectionDAGTest, KnownNeverZero_Select) {
   EXPECT_FALSE(DAG->isKnownNeverZero(VSelect444Big, DemandAll));
   EXPECT_TRUE(DAG->isKnownNeverZero(VSelect4444, DemandAll));
 }
-
-TEST_F(AArch64SelectionDAGTest, KnownNeverZero_Div) {
-  SDLoc Loc;
-  auto Cst0 = DAG->getConstant(0, Loc, MVT::i32);
-  auto Cst1 = DAG->getConstant(1, Loc, MVT::i32);
-  auto Cst2 = DAG->getConstant(2, Loc, MVT::i32);
-
-  auto Cst4 = DAG->getConstant(4, Loc, MVT::i32);
-  auto Neg1 = DAG->getNode(ISD::SUB, Loc, MVT::i32, Cst0, Cst1);
-  auto Neg4 = DAG->getNode(ISD::SUB, Loc, MVT::i32, Cst0, Cst4);
-
-  auto UDiv04 =
-      DAG->getNode(ISD::UDIV, Loc, MVT::i32, Cst0, Cst4, SDNodeFlags::Exact);
-  auto UDiv41 =
-      DAG->getNode(ISD::UDIV, Loc, MVT::i32, Cst4, Cst1, SDNodeFlags::Exact);
-  auto UDivNeg41 =
-      DAG->getNode(ISD::UDIV, Loc, MVT::i32, Neg4, Cst1, SDNodeFlags::Exact);
-  auto UDiv4Neg1 =
-      DAG->getNode(ISD::UDIV, Loc, MVT::i32, Cst4, Neg1, SDNodeFlags::Exact);
-  auto UDivNeg1Neg4 =
-      DAG->getNode(ISD::UDIV, Loc, MVT::i32, Neg1, Neg4, SDNodeFlags::Exact);
-
-  EXPECT_FALSE(DAG->isKnownNeverZero(UDiv04));
-  EXPECT_TRUE(DAG->isKnownNeverZero(UDiv41));
-  EXPECT_TRUE(DAG->isKnownNeverZero(UDivNeg41));
-  EXPECT_FALSE(DAG->isKnownNeverZero(UDiv4Neg1));
-  EXPECT_TRUE(DAG->isKnownNeverZero(UDivNeg1Neg4));
-
-  auto SDiv04 =
-      DAG->getNode(ISD::SDIV, Loc, MVT::i32, Cst0, Cst4, SDNodeFlags::Exact);
-  auto SDiv41 =
-      DAG->getNode(ISD::SDIV, Loc, MVT::i32, Cst4, Cst1, SDNodeFlags::Exact);
-  auto SDivNeg41 =
-      DAG->getNode(ISD::SDIV, Loc, MVT::i32, Neg4, Cst1, SDNodeFlags::Exact);
-  auto SDiv4Neg1 =
-      DAG->getNode(ISD::SDIV, Loc, MVT::i32, Cst4, Neg1, SDNodeFlags::Exact);
-  auto SDivNeg1Neg4 =
-      DAG->getNode(ISD::SDIV, Loc, MVT::i32, Neg1, Neg4, SDNodeFlags::Exact);
-
-  EXPECT_FALSE(DAG->isKnownNeverZero(SDiv04));
-  EXPECT_TRUE(DAG->isKnownNeverZero(SDiv41));
-  EXPECT_TRUE(DAG->isKnownNeverZero(SDivNeg41));
-  EXPECT_TRUE(DAG->isKnownNeverZero(SDiv4Neg1));
-  EXPECT_FALSE(DAG->isKnownNeverZero(SDivNeg1Neg4));
-
-  auto VecVT = MVT::v2i16;
-  auto Vec00 = DAG->getBuildVector(VecVT, Loc, {Cst0, Cst0});
-  auto Vec40 = DAG->getBuildVector(VecVT, Loc, {Cst4, Cst0});
-  auto Vec14 = DAG->getBuildVector(VecVT, Loc, {Cst1, Cst4});
-  auto Vec42 = DAG->getBuildVector(VecVT, Loc, {Cst4, Cst2});
-  auto Vec44 = DAG->getBuildVector(VecVT, Loc, {Cst4, Cst4});
-  auto VecNeg1Neg4 = DAG->getBuildVector(VecVT, Loc, {Neg1, Neg4});
-
-  APInt DemandLo(2, 1);
-  APInt DemandHi(2, 2);
-  APInt DemandAll(2, 3);
-
-  auto VUDiv4044 =
-      DAG->getNode(ISD::UDIV, Loc, VecVT, Vec40, Vec44, SDNodeFlags::Exact);
-  auto VUDiv1442 =
-      DAG->getNode(ISD::UDIV, Loc, VecVT, Vec14, Vec42, SDNodeFlags::Exact);
-  auto VUDiv4414 =
-      DAG->getNode(ISD::UDIV, Loc, VecVT, Vec44, Vec14, SDNodeFlags::Exact);
-  auto VUDiv14Neg1Neg4 = DAG->getNode(ISD::UDIV, Loc, VecVT, Vec14, VecNeg1Neg4,
-                                      SDNodeFlags::Exact);
-
-  EXPECT_TRUE(DAG->isKnownNeverZero(VUDiv4044, DemandLo));
-  EXPECT_FALSE(DAG->isKnownNeverZero(VUDiv1442, DemandLo));
-
-  EXPECT_FALSE(DAG->isKnownNeverZero(VUDiv4044, DemandHi));
-  EXPECT_TRUE(DAG->isKnownNeverZero(VUDiv1442, DemandHi));
-
-  EXPECT_FALSE(DAG->isKnownNeverZero(VUDiv14Neg1Neg4, DemandAll));
-  EXPECT_TRUE(DAG->isKnownNeverZero(VUDiv4414, DemandAll));
-
-  auto VSDiv0044 =
-      DAG->getNode(ISD::SDIV, Loc, VecVT, Vec00, Vec44, SDNodeFlags::Exact);
-  auto VSDiv4044 =
-      DAG->getNode(ISD::SDIV, Loc, VecVT, Vec40, Vec44, SDNodeFlags::Exact);
-  auto VSDiv1442 =
-      DAG->getNode(ISD::SDIV, Loc, VecVT, Vec14, Vec42, SDNodeFlags::Exact);
-  auto VSDiv14Neg1Neg4 = DAG->getNode(ISD::SDIV, Loc, VecVT, Vec14, VecNeg1Neg4,
-                                      SDNodeFlags::Exact);
-
-  EXPECT_TRUE(DAG->isKnownNeverZero(VSDiv4044, DemandLo));
-  EXPECT_FALSE(DAG->isKnownNeverZero(VSDiv1442, DemandLo));
-
-  EXPECT_FALSE(DAG->isKnownNeverZero(VSDiv4044, DemandHi));
-  EXPECT_TRUE(DAG->isKnownNeverZero(VSDiv1442, DemandHi));
-
-  EXPECT_TRUE(DAG->isKnownNeverZero(VSDiv14Neg1Neg4, DemandAll));
-  EXPECT_FALSE(DAG->isKnownNeverZero(VSDiv0044, DemandAll));
-}
 } // end namespace llvm

>From cdf3b0696d08a055312fa14c09440a71df4682cf Mon Sep 17 00:00:00 2001
From: Ayokunle Amodu <ayokunle321 at gmail.com>
Date: Tue, 3 Mar 2026 13:06:23 -0700
Subject: [PATCH 7/7] add updated test

---
 llvm/test/CodeGen/X86/known-never-zero.ll | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/llvm/test/CodeGen/X86/known-never-zero.ll b/llvm/test/CodeGen/X86/known-never-zero.ll
index 25c0d87110aba..f691aef3698e8 100644
--- a/llvm/test/CodeGen/X86/known-never-zero.ll
+++ b/llvm/test/CodeGen/X86/known-never-zero.ll
@@ -1511,7 +1511,9 @@ define i32 @udiv_known_nonzero_vec(<4 x i32> %xx, <4 x i32> %y, ptr %p) nounwind
 ; X86-NEXT:    punpckldq {{.*#+}} xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
 ; X86-NEXT:    punpcklqdq {{.*#+}} xmm0 = xmm0[0],xmm2[0]
 ; X86-NEXT:    movdqa %xmm0, (%ecx)
-; X86-NEXT:    rep bsfl %eax, %eax
+; X86-NEXT:    bsfl %eax, %ecx
+; X86-NEXT:    movl $32, %eax
+; X86-NEXT:    cmovnel %ecx, %eax
 ; X86-NEXT:    popl %esi
 ; X86-NEXT:    retl
 ;
@@ -1540,8 +1542,9 @@ define i32 @udiv_known_nonzero_vec(<4 x i32> %xx, <4 x i32> %y, ptr %p) nounwind
 ; X64-NEXT:    divl %ecx
 ; X64-NEXT:    vpinsrd $3, %eax, %xmm2, %xmm0
 ; X64-NEXT:    vmovdqa %xmm0, (%rdi)
-; X64-NEXT:    vmovd %xmm0, %eax
-; X64-NEXT:    rep bsfl %eax, %eax
+; X64-NEXT:    vmovd %xmm0, %ecx
+; X64-NEXT:    movl $32, %eax
+; X64-NEXT:    rep bsfl %ecx, %eax
 ; X64-NEXT:    retq
   %x = or <4 x i32> %xx, <i32 64, i32 -1, i32 -1, i32 -1>
   %z = udiv exact <4 x i32> %x, %y
@@ -1633,7 +1636,9 @@ define i32 @sdiv_known_nonzero_vec(<4 x i32> %xx, <4 x i32> %y, ptr %p) nounwind
 ; X86-NEXT:    punpckldq {{.*#+}} xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
 ; X86-NEXT:    punpcklqdq {{.*#+}} xmm0 = xmm0[0],xmm2[0]
 ; X86-NEXT:    movdqa %xmm0, (%ecx)
-; X86-NEXT:    rep bsfl %eax, %eax
+; X86-NEXT:    bsfl %eax, %ecx
+; X86-NEXT:    movl $32, %eax
+; X86-NEXT:    cmovnel %ecx, %eax
 ; X86-NEXT:    popl %esi
 ; X86-NEXT:    retl
 ;
@@ -1662,8 +1667,9 @@ define i32 @sdiv_known_nonzero_vec(<4 x i32> %xx, <4 x i32> %y, ptr %p) nounwind
 ; X64-NEXT:    idivl %ecx
 ; X64-NEXT:    vpinsrd $3, %eax, %xmm2, %xmm0
 ; X64-NEXT:    vmovdqa %xmm0, (%rdi)
-; X64-NEXT:    vmovd %xmm0, %eax
-; X64-NEXT:    rep bsfl %eax, %eax
+; X64-NEXT:    vmovd %xmm0, %ecx
+; X64-NEXT:    movl $32, %eax
+; X64-NEXT:    rep bsfl %ecx, %eax
 ; X64-NEXT:    retq
   %x = or <4 x i32> %xx, <i32 64, i32 -1, i32 -1, i32 -1>
   %z = sdiv exact <4 x i32> %x, %y



More information about the llvm-commits mailing list