[PATCH] D98979: [LegalizeDAG] Add asserts to verify the types of custom legalized operation matches the original node.

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 19 12:12:35 PDT 2021


craig.topper created this revision.
craig.topper added reviewers: RKSimon, spatel, frasercrmck, efriedma.
Herald added subscribers: luismarques, pengfei, s.egerton, PkmX, simoncook, hiraditya, kristof.beyls.
craig.topper requested review of this revision.
Herald added a project: LLVM.

We've messed this up a few times recently on RISCV. Experiments
with these asserts found a couple issues on other targets as well.
They've all been cleaned up now so we can put in these asserts to
catch future issues

I had to waive Glue because ADDC/ADDE/etc legalization replaces
Glue with i32 on at least AArch64. X86 used to do the same before
we switched to ADDCARRY. So I guess that's just how that works.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D98979

Files:
  llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp


Index: llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
+++ llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
@@ -1259,6 +1259,9 @@
           return;
 
         if (Node->getNumValues() == 1) {
+          assert((Res.getValueType() == Node->getValueType(0) ||
+                  Node->getValueType(0) == MVT::Glue) &&
+                 "Type mismatch for custom legalized operation");
           LLVM_DEBUG(dbgs() << "Successfully custom legalized node\n");
           // We can just directly replace this node with the lowered value.
           ReplaceNode(SDValue(Node, 0), Res);
@@ -1266,8 +1269,12 @@
         }
 
         SmallVector<SDValue, 8> ResultVals;
-        for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i)
+        for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) {
+          assert((Res->getValueType(i) == Node->getValueType(i) ||
+                  Node->getValueType(i) == MVT::Glue) &&
+                 "Type mismatch for custom legalized operation");
           ResultVals.push_back(Res.getValue(i));
+        }
         LLVM_DEBUG(dbgs() << "Successfully custom legalized node\n");
         ReplaceNode(Node, ResultVals.data());
         return;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98979.331976.patch
Type: text/x-patch
Size: 1304 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210319/f0f1d266/attachment.bin>


More information about the llvm-commits mailing list