[llvm] c401dbd - [llvm][IROutliner] Account for return void in sort comparator

David Spickett via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 5 02:36:51 PDT 2022


Author: David Spickett
Date: 2022-08-05T09:36:43Z
New Revision: c401dbde71fdfdbdb0e77df54429408bab903991

URL: https://github.com/llvm/llvm-project/commit/c401dbde71fdfdbdb0e77df54429408bab903991
DIFF: https://github.com/llvm/llvm-project/commit/c401dbde71fdfdbdb0e77df54429408bab903991.diff

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

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 and here, we expect
to see one return void or multiple return constant integer.

Don't sort if we have 1 item, but do assert that it is the 1
ret void we expect. In the comparator, assert that neither
Value is a nullptr in case one ended up in a the list somehow.

Reviewed By: AndrewLitteken

Differential Revision: https://reviews.llvm.org/D130230

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/IROutliner.cpp b/llvm/lib/Transforms/IPO/IROutliner.cpp
index 28bc43aa1633e..076076b076f6b 100644
--- a/llvm/lib/Transforms/IPO/IROutliner.cpp
+++ b/llvm/lib/Transforms/IPO/IROutliner.cpp
@@ -169,7 +169,15 @@ static void getSortedConstantKeys(std::vector<Value *> &SortedKeys,
   for (auto &VtoBB : Map)
     SortedKeys.push_back(VtoBB.first);
 
+  // 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.");
+    return;
+  }
+
   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?");


        


More information about the llvm-commits mailing list