summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjorn Pettersson <bjorn.a.pettersson@ericsson.com>2018-06-20 16:06:09 +0000
committerBjorn Pettersson <bjorn.a.pettersson@ericsson.com>2018-06-20 16:06:09 +0000
commit7bf676662af29a3bf9b8cdb8fae9c26c95c352f7 (patch)
tree0142f75258433c06946b938abfc135abe916fd8f
parent6d163c5feb2b4cc7d1ffac82800caab74da93a68 (diff)
downloadbcm5719-llvm-7bf676662af29a3bf9b8cdb8fae9c26c95c352f7.tar.gz
bcm5719-llvm-7bf676662af29a3bf9b8cdb8fae9c26c95c352f7.zip
[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
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp7
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h3
-rw-r--r--llvm/test/CodeGen/X86/legalize-types-remapid.ll16
3 files changed, 23 insertions, 3 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp
index 77e167dfb08..a9f144c06e9 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp
@@ -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,7 +653,8 @@ void DAGTypeLegalizer::ReplaceValueWith(SDValue From, SDValue To) {
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(SDValue From, SDValue To) {
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.
}
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h b/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h
index 6d577adc6f4..e4d4aac3340 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h
@@ -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));
diff --git a/llvm/test/CodeGen/X86/legalize-types-remapid.ll b/llvm/test/CodeGen/X86/legalize-types-remapid.ll
new file mode 100644
index 00000000000..d24ec2d3b55
--- /dev/null
+++ b/llvm/test/CodeGen/X86/legalize-types-remapid.ll
@@ -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
+}
OpenPOWER on IntegriCloud