-
Notifications
You must be signed in to change notification settings - Fork 12.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EarlyCSE: fix CmpPredicate duplicate-hashing (#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 #119893.
- Loading branch information
Showing
4 changed files
with
23 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 | ||
; RUN: opt -passes=early-cse -S %s | FileCheck %s | ||
|
||
define i32 @samesign_hash_bug(i16 %v) { | ||
; CHECK-LABEL: define i32 @samesign_hash_bug( | ||
; CHECK-SAME: i16 [[V:%.*]]) { | ||
; CHECK-NEXT: [[ZEXT:%.*]] = zext i16 [[V]] to i32 | ||
; CHECK-NEXT: [[ICMP_SAMESIGN:%.*]] = icmp ugt i32 [[ZEXT]], 31 | ||
; CHECK-NEXT: [[SELECT_ICMP_SAMESIGN:%.*]] = select i1 [[ICMP_SAMESIGN]], i32 0, i32 1 | ||
; CHECK-NEXT: [[SELECT_ICMP:%.*]] = select i1 [[ICMP_SAMESIGN]], i32 1, i32 0 | ||
; CHECK-NEXT: ret i32 [[SELECT_ICMP]] | ||
; | ||
%zext = zext i16 %v to i32 | ||
%icmp.samesign = icmp samesign ugt i32 %zext, 31 | ||
%select.icmp.samesign = select i1 %icmp.samesign, i32 0, i32 1 | ||
%ashr = ashr i32 0, %select.icmp.samesign | ||
%icmp = icmp ugt i32 %zext, 31 | ||
%select.icmp = select i1 %icmp, i32 1, i32 0 | ||
%ret = add i32 %ashr, %select.icmp | ||
ret i32 %ret | ||
} |