[llvm] r335141 - [DAG] Don't map a TableId to itself in the ReplacedValues map
Bjorn Pettersson via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 20 09:06:10 PDT 2018
Author: bjope
Date: Wed Jun 20 09:06:09 2018
New Revision: 335141
URL: http://llvm.org/viewvc/llvm-project?rev=335141&view=rev
Log:
[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
Added:
llvm/trunk/test/CodeGen/X86/legalize-types-remapid.ll
Modified:
llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp
llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeTypes.h
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp?rev=335141&r1=335140&r2=335141&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp Wed Jun 20 09:06:09 2018
@@ -575,6 +575,7 @@ void DAGTypeLegalizer::RemapValue(SDValu
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,7 +653,8 @@ void DAGTypeLegalizer::ReplaceValueWith(
auto FromId = getTableId(From);
auto ToId = getTableId(To);
- ReplacedValues[FromId] = ToId;
+ if (FromId != ToId)
+ ReplacedValues[FromId] = ToId;
DAG.ReplaceAllUsesOfValueWith(From, To);
// Process the list of nodes that need to be reanalyzed.
@@ -685,7 +687,8 @@ void DAGTypeLegalizer::ReplaceValueWith(
auto OldValId = getTableId(OldVal);
auto NewValId = getTableId(NewVal);
DAG.ReplaceAllUsesOfValueWith(OldVal, NewVal);
- ReplacedValues[OldValId] = NewValId;
+ if (OldValId != NewValId)
+ ReplacedValues[OldValId] = NewValId;
}
// The original node continues to exist in the DAG, marked NewNode.
}
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeTypes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeTypes.h?rev=335141&r1=335140&r2=335141&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeTypes.h (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeTypes.h Wed Jun 20 09:06:09 2018
@@ -186,7 +186,8 @@ public:
TableId NewId = getTableId(SDValue(New, i));
TableId OldId = getTableId(SDValue(Old, i));
- ReplacedValues[OldId] = NewId;
+ if (OldId != NewId)
+ ReplacedValues[OldId] = NewId;
// Delete Node from tables.
ValueToIdMap.erase(SDValue(Old, i));
Added: llvm/trunk/test/CodeGen/X86/legalize-types-remapid.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/legalize-types-remapid.ll?rev=335141&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/legalize-types-remapid.ll (added)
+++ llvm/trunk/test/CodeGen/X86/legalize-types-remapid.ll Wed Jun 20 09:06:09 2018
@@ -0,0 +1,16 @@
+; RUN: llc -mtriple=i386 -mcpu=generic -O0 -o /dev/null %s
+
+ at c = global i32 0
+ at 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
+}
More information about the llvm-commits
mailing list