Skip to content

Commit 24b7c71

Browse files
artagnonsearlmc1
authored andcommitted
EarlyCSE: fix CmpPredicate duplicate-hashing (llvm#119902)
Strip hash_value() for CmpPredicate, as different callers have different hashing use-cases. In this case, there is just one caller, namely EarlyCSE, which calls hash_combine() on a CmpPredicate, which used to call hash_combine() on a CmpInst::Predicate prior to 4a0d53a (PatternMatch: migrate to CmpPredicate). This has uncovered a bug where two icmp instructions differing in just the fact that one of them has the samesign flag on it are hashed differently, leading to divergent hashing, and a crash. Fix this crash by dropping samesign information on icmp instructions before hashing them, preserving the former behavior. Fixes llvm#119893. Change-Id: Iaa84f654b5f0cbe9792a78a14ba92af2ebaf5c18
1 parent 629442a commit 24b7c71

File tree

3 files changed

+2
-11
lines changed

3 files changed

+2
-11
lines changed

llvm/include/llvm/IR/CmpPredicate.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,7 @@ class CmpPredicate {
7171

7272
/// Get the swapped predicate of a CmpInst.
7373
static CmpPredicate getSwapped(const CmpInst *Cmp);
74-
75-
/// Provided to facilitate storing a CmpPredicate in data structures that
76-
/// require hashing.
77-
friend hash_code hash_value(const CmpPredicate &Arg); // NOLINT
7874
};
79-
80-
[[nodiscard]] hash_code hash_value(const CmpPredicate &Arg);
8175
} // namespace llvm
8276

8377
#endif

llvm/lib/IR/Instructions.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3946,10 +3946,6 @@ CmpPredicate CmpPredicate::getSwapped(const CmpInst *Cmp) {
39463946
return getSwapped(get(Cmp));
39473947
}
39483948

3949-
hash_code llvm::hash_value(const CmpPredicate &Arg) { // NOLINT
3950-
return hash_combine(Arg.Pred, Arg.HasSameSign);
3951-
}
3952-
39533949
//===----------------------------------------------------------------------===//
39543950
// SwitchInst Implementation
39553951
//===----------------------------------------------------------------------===//

llvm/lib/Transforms/Scalar/EarlyCSE.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,8 @@ static unsigned getHashValueImpl(SimpleValue Val) {
290290
Pred = CmpInst::getInversePredicate(Pred);
291291
std::swap(A, B);
292292
}
293-
return hash_combine(Inst->getOpcode(), Pred, X, Y, A, B);
293+
return hash_combine(Inst->getOpcode(),
294+
static_cast<CmpInst::Predicate>(Pred), X, Y, A, B);
294295
}
295296

296297
if (CastInst *CI = dyn_cast<CastInst>(Inst))

0 commit comments

Comments
 (0)