Skip to content

Commit 98bfdac

Browse files
nikictru
authored andcommitted
[BranchFolding] Remove dubious assert from operator< (#71639)
`MergePotentialElts::operator<` asserts that the two elements being compared are not equal. However, sorting functions are allowed to invoke the comparison function with equal arguments (though they usually don't for efficiency reasons). There is an existing special-case that disables the assert if _GLIBCXX_DEBUG is used, which may invoke the comparator with equal args to verify strict weak ordering. I believe libc++ also has strict weak ordering checks under some options nowadays. Recently, #71312 was reported, where a change to glibc's qsort_r implementation can also result in comparison between equal elements. From what I understood, this is an inefficiency that will be fixed on the glibc side as well, but I think at this point we should just remove this assertion. Fixes #71312. (cherry picked from commit 74a76a2)
1 parent 12c6ee8 commit 98bfdac

File tree

1 file changed

+0
-6
lines changed

1 file changed

+0
-6
lines changed

llvm/lib/CodeGen/BranchFolding.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -485,13 +485,7 @@ BranchFolder::MergePotentialsElt::operator<(const MergePotentialsElt &o) const {
485485
return true;
486486
if (getBlock()->getNumber() > o.getBlock()->getNumber())
487487
return false;
488-
// _GLIBCXX_DEBUG checks strict weak ordering, which involves comparing
489-
// an object with itself.
490-
#ifndef _GLIBCXX_DEBUG
491-
llvm_unreachable("Predecessor appears twice");
492-
#else
493488
return false;
494-
#endif
495489
}
496490

497491
/// CountTerminators - Count the number of terminators in the given

0 commit comments

Comments
 (0)