[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 Jul 21 01:38:41 PDT 2022


DavidSpickett created this revision.
Herald added subscribers: ormris, hiraditya.
Herald added a project: All.
DavidSpickett requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This fixes 69 llvm tests that failed when EXPENSIVE_CHECKS was enabled.
llvm/test/Transforms/IROutliner/outlining-commutative-operands-opposite-order.ll
is one example.

When we have EXPENSIVE_CHECKS, _GLIBCXX_DEBUG is defined. This means
that libstdc++ will call the compare function to check if it is
implemented correctly (that !(a < a) is true).

This happens even if there is only one item, as is the case in many
tests where there is a "ret void" (not sure if you can have multiple
"ret void" but no test appears to at least).

To fix this I've added null checks to the comparator that will cause
all "void" to be < any ConstantInt.


Repository:
  rG LLVM Github Monorepo

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
@@ -170,6 +170,15 @@
     SortedKeys.push_back(VtoBB.first);
 
   stable_sort(SortedKeys, [](const Value *LHS, const Value *RHS) {
+    // We may be dealing with a return void here in which case Value* will be
+    // nullptr. Assume that void is < any ConstantInt.
+    if ((LHS == nullptr) && (RHS == nullptr))
+      return false;
+    if (LHS == nullptr)
+      return true;
+    if (RHS == nullptr)
+      return false;
+
     const ConstantInt *LHSC = dyn_cast<ConstantInt>(LHS);
     const ConstantInt *RHSC = dyn_cast<ConstantInt>(RHS);
     assert(RHSC && "Not a constant integer in return value?");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130230.446389.patch
Type: text/x-patch
Size: 809 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220721/75cc3266/attachment.bin>


More information about the llvm-commits mailing list