[PATCH] D130230: [llvm][IROutliner] Account for return void in sort comparator

David Spickett via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 4 02:40:15 PDT 2022


DavidSpickett updated this revision to Diff 449916.
DavidSpickett added a comment.

Implement suggested changes.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130230/new/

https://reviews.llvm.org/D130230

Files:
  llvm/lib/Transforms/IPO/IROutliner.cpp


Index: llvm/lib/Transforms/IPO/IROutliner.cpp
===================================================================
--- llvm/lib/Transforms/IPO/IROutliner.cpp
+++ llvm/lib/Transforms/IPO/IROutliner.cpp
@@ -169,14 +169,21 @@
   for (auto &VtoBB : Map)
     SortedKeys.push_back(VtoBB.first);
 
-  stable_sort(SortedKeys, [](const Value *LHS, const Value *RHS) {
-    const ConstantInt *LHSC = dyn_cast<ConstantInt>(LHS);
-    const ConstantInt *RHSC = dyn_cast<ConstantInt>(RHS);
-    assert(RHSC && "Not a constant integer in return value?");
-    assert(LHSC && "Not a constant integer in return value?");
-
-    return LHSC->getLimitedValue() < RHSC->getLimitedValue();
-  });
+  // Here we expect to have either 1 value that is void (nullptr) or multiple
+  // values that are all constant integers.
+  if (SortedKeys.size() == 1)
+    assert(!SortedKeys[0] && "Expected a single void value.");
+  else {
+    stable_sort(SortedKeys, [](const Value *LHS, const Value *RHS) {
+      assert(LHS && RHS && "Expected non void values.");
+      const ConstantInt *LHSC = dyn_cast<ConstantInt>(LHS);
+      const ConstantInt *RHSC = dyn_cast<ConstantInt>(RHS);
+      assert(RHSC && "Not a constant integer in return value?");
+      assert(LHSC && "Not a constant integer in return value?");
+
+      return LHSC->getLimitedValue() < RHSC->getLimitedValue();
+    });
+  }
 }
 
 Value *OutlinableRegion::findCorrespondingValueIn(const OutlinableRegion &Other,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130230.449916.patch
Type: text/x-patch
Size: 1456 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220804/a7ae87d9/attachment.bin>


More information about the llvm-commits mailing list