Skip to content

Commit

Permalink
Fix for #1767.
Browse files Browse the repository at this point in the history
  • Loading branch information
DeepakRajendrakumaran authored and Dmitry Babokin committed May 28, 2020
1 parent 763adc5 commit 6252389
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
79 changes: 79 additions & 0 deletions llvm_patches/10_0_Fix_For_1767.patch
@@ -0,0 +1,79 @@
# This patch is required to fix the crash referenced to in #1767.
# It is a port of the following llvm 11.0 commit : https://reviews.llvm.org/D76994.
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp
index 63ddb59fce6..822da218326 100644
--- lib/CodeGen/SelectionDAG/LegalizeTypes.cpp
+++ lib/CodeGen/SelectionDAG/LegalizeTypes.cpp
@@ -173,7 +173,7 @@ void DAGTypeLegalizer::PerformExpensiveChecks() {
}
}
}
-
+#ifndef NDEBUG
// Checked that NewNodes are only used by other NewNodes.
for (unsigned i = 0, e = NewNodes.size(); i != e; ++i) {
SDNode *N = NewNodes[i];
@@ -181,6 +181,7 @@ void DAGTypeLegalizer::PerformExpensiveChecks() {
UI != UE; ++UI)
assert(UI->getNodeId() == NewNode && "NewNode used by non-NewNode!");
}
+#endif
}

/// This is the main entry point for the type legalizer. This does a top-down
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h b/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h
index faae14444d5..b908c5c58e9 100644
--- lib/CodeGen/SelectionDAG/LegalizeTypes.h
+++ lib/CodeGen/SelectionDAG/LegalizeTypes.h
@@ -155,7 +155,9 @@ private:
const SDValue &getSDValue(TableId &Id) {
RemapId(Id);
assert(Id && "TableId should be non-zero");
- return IdToValueMap[Id];
+ auto I = IdToValueMap.find(Id);
+ assert(I != IdToValueMap.end() && "cannot find Id in map");
+ return I->second;
}

public:
@@ -172,24 +174,29 @@ public:
bool run();

void NoteDeletion(SDNode *Old, SDNode *New) {
+ assert(Old != New && "node replaced with self");
for (unsigned i = 0, e = Old->getNumValues(); i != e; ++i) {
TableId NewId = getTableId(SDValue(New, i));
TableId OldId = getTableId(SDValue(Old, i));

- if (OldId != NewId)
+ if (OldId != NewId) {
ReplacedValues[OldId] = NewId;

- // Delete Node from tables.
+ // Delete Node from tables. We cannot do this when OldId == NewId,
+ // because NewId can still have table references to it in
+ // ReplacedValues.
+ IdToValueMap.erase(OldId);
+ PromotedIntegers.erase(OldId);
+ ExpandedIntegers.erase(OldId);
+ SoftenedFloats.erase(OldId);
+ PromotedFloats.erase(OldId);
+ ExpandedFloats.erase(OldId);
+ ScalarizedVectors.erase(OldId);
+ SplitVectors.erase(OldId);
+ WidenedVectors.erase(OldId);
+ }
+
ValueToIdMap.erase(SDValue(Old, i));
- IdToValueMap.erase(OldId);
- PromotedIntegers.erase(OldId);
- ExpandedIntegers.erase(OldId);
- SoftenedFloats.erase(OldId);
- PromotedFloats.erase(OldId);
- ExpandedFloats.erase(OldId);
- ScalarizedVectors.erase(OldId);
- SplitVectors.erase(OldId);
- WidenedVectors.erase(OldId);
}
}

7 changes: 7 additions & 0 deletions tests/lit-tests/1767.ispc
@@ -0,0 +1,7 @@
// RUN: %{ispc} --target=avx2-i32x16 %s -o %t.o
// REQUIRES: X86_ENABLED
extern uniform bool arr_4[17];
export void test(uniform int64 var_1, uniform bool var_15) {
foreach (i_0 = var_1... 16U)
arr_4[i_0] = !(varying bool)reduce_min(180) ? 5923697687793782713ULL : (varying bool)var_15;
}

0 comments on commit 6252389

Please sign in to comment.