[DAG] Don't map a TableId to itself in the ReplacedValues map

Summary:
Found some regressions (infinite loop in DAGTypeLegalizer::RemapId)
after r334880. This patch makes sure that we do map a TableId to
itself.

Reviewers: niravd

Reviewed By: niravd

Subscribers: llvm-commits

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

llvm-svn: 335141
This commit is contained in:
Bjorn Pettersson 2018-06-20 16:06:09 +00:00
parent 6d163c5feb
commit 7bf676662a
3 changed files with 23 additions and 3 deletions

View File

@ -575,6 +575,7 @@ void DAGTypeLegalizer::RemapValue(SDValue &V) {
void DAGTypeLegalizer::RemapId(TableId &Id) {
auto I = ReplacedValues.find(Id);
if (I != ReplacedValues.end()) {
assert(Id != I->second && "Id is mapped to itself.");
// Use path compression to speed up future lookups if values get multiply
// replaced with other values.
RemapId(I->second);
@ -652,6 +653,7 @@ void DAGTypeLegalizer::ReplaceValueWith(SDValue From, SDValue To) {
auto FromId = getTableId(From);
auto ToId = getTableId(To);
if (FromId != ToId)
ReplacedValues[FromId] = ToId;
DAG.ReplaceAllUsesOfValueWith(From, To);
@ -685,6 +687,7 @@ void DAGTypeLegalizer::ReplaceValueWith(SDValue From, SDValue To) {
auto OldValId = getTableId(OldVal);
auto NewValId = getTableId(NewVal);
DAG.ReplaceAllUsesOfValueWith(OldVal, NewVal);
if (OldValId != NewValId)
ReplacedValues[OldValId] = NewValId;
}
// The original node continues to exist in the DAG, marked NewNode.

View File

@ -186,6 +186,7 @@ public:
TableId NewId = getTableId(SDValue(New, i));
TableId OldId = getTableId(SDValue(Old, i));
if (OldId != NewId)
ReplacedValues[OldId] = NewId;
// Delete Node from tables.

View File

@ -0,0 +1,16 @@
; RUN: llc -mtriple=i386 -mcpu=generic -O0 -o /dev/null %s
@c = global i32 0
@d = global <2 x i64> zeroinitializer
define void @test() {
bb1:
%t0 = load <2 x i64>, <2 x i64>* @d
%t0.i0 = extractelement <2 x i64> %t0, i32 0
%t0.i0.cast = bitcast i64 %t0.i0 to <2 x i32>
%t0.i0.cast.i0 = extractelement <2 x i32> %t0.i0.cast, i32 0
store volatile i32 %t0.i0.cast.i0, i32* @c
%t0.i0.cast.i1 = extractelement <2 x i32> %t0.i0.cast, i32 1
store volatile i32 %t0.i0.cast.i1, i32* @c
ret void
}