[llvm] 78d85c2 - [AssumeBundles] fix crashes
via llvm-commits
llvm-commits at lists.llvm.org
Mon May 11 03:23:36 PDT 2020
Author: Tyker
Date: 2020-05-11T11:52:21+02:00
New Revision: 78d85c20919ff0a92e2a4e83c9be65a9cd493c0c
URL: https://github.com/llvm/llvm-project/commit/78d85c20919ff0a92e2a4e83c9be65a9cd493c0c
DIFF: https://github.com/llvm/llvm-project/commit/78d85c20919ff0a92e2a4e83c9be65a9cd493c0c.diff
LOG: [AssumeBundles] fix crashes
Summary:
this patch fixe crash/asserts found in the test-suite.
the AssumeptionCache cannot be assumed to have all assumes contrary to what i tought.
prevent generation of information for terminators, because this can create broken IR in transfromation where we insert the new terminator before removing the old one.
Reviewers: jdoerfert
Reviewed By: jdoerfert
Subscribers: hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D79458
Added:
Modified:
llvm/lib/Analysis/AssumeBundleQueries.cpp
llvm/lib/Transforms/Utils/AssumeBundleBuilder.cpp
llvm/test/Transforms/Util/assume-builder.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/AssumeBundleQueries.cpp b/llvm/lib/Analysis/AssumeBundleQueries.cpp
index aa56bfd0344f..e9da1e607b45 100644
--- a/llvm/lib/Analysis/AssumeBundleQueries.cpp
+++ b/llvm/lib/Analysis/AssumeBundleQueries.cpp
@@ -152,10 +152,6 @@ llvm::getKnowledgeForValue(const Value *V,
const CallBase::BundleOpInfo *)>
Filter) {
if (AC) {
-#ifndef NDEBUG
- RetainedKnowledge RKCheck =
- getKnowledgeForValue(V, AttrKinds, nullptr, Filter);
-#endif
for (AssumptionCache::ResultElem &Elem : AC->assumptionsFor(V)) {
IntrinsicInst *II = cast_or_null<IntrinsicInst>(Elem.Assume);
if (!II || Elem.Index == AssumptionCache::ExprResultIdx)
@@ -163,12 +159,9 @@ llvm::getKnowledgeForValue(const Value *V,
if (RetainedKnowledge RK = getKnowledgeFromBundle(
*II, II->bundle_op_info_begin()[Elem.Index]))
if (is_contained(AttrKinds, RK.AttrKind) &&
- Filter(RK, II, &II->bundle_op_info_begin()[Elem.Index])) {
- assert(!!RKCheck && "invalid Assumption cache");
+ Filter(RK, II, &II->bundle_op_info_begin()[Elem.Index]))
return RK;
- }
}
- assert(!RKCheck && "invalid Assumption cache");
return RetainedKnowledge::none();
}
for (auto &U : V->uses()) {
diff --git a/llvm/lib/Transforms/Utils/AssumeBundleBuilder.cpp b/llvm/lib/Transforms/Utils/AssumeBundleBuilder.cpp
index 4e47dd82d0d9..ee5e142ccf43 100644
--- a/llvm/lib/Transforms/Utils/AssumeBundleBuilder.cpp
+++ b/llvm/lib/Transforms/Utils/AssumeBundleBuilder.cpp
@@ -201,8 +201,9 @@ IntrinsicInst *llvm::buildAssumeFromInst(Instruction *I) {
return Builder.build();
}
-void llvm::salvageKnowledge(Instruction *I, AssumptionCache *AC, DominatorTree* DT) {
- if (!EnableKnowledgeRetention)
+void llvm::salvageKnowledge(Instruction *I, AssumptionCache *AC,
+ DominatorTree *DT) {
+ if (!EnableKnowledgeRetention || I->isTerminator())
return;
AssumeBuilderState Builder(I->getModule(), I, AC, DT);
Builder.addInstruction(I);
diff --git a/llvm/test/Transforms/Util/assume-builder.ll b/llvm/test/Transforms/Util/assume-builder.ll
index 41126a7ed618..cfa8a07d51da 100644
--- a/llvm/test/Transforms/Util/assume-builder.ll
+++ b/llvm/test/Transforms/Util/assume-builder.ll
@@ -901,3 +901,81 @@ define dso_local i32 @test4A(i32* %0, i32* %1, i32 %2, i32 %3) {
12: ; preds = %6, %4
ret i32 0
}
+
+declare void @may_throwv2(i32* %P)
+
+define dso_local i32 @terminator(i32* %P) personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
+; BASIC-LABEL: define {{[^@]+}}@terminator
+; BASIC-SAME: (i32* [[P:%.*]]) personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
+; BASIC-NEXT: invoke void @may_throwv2(i32* nonnull [[P]])
+; BASIC-NEXT: to label [[EXIT:%.*]] unwind label [[CATCH:%.*]]
+; BASIC: Catch:
+; BASIC-NEXT: [[V:%.*]] = landingpad { i8*, i32 }
+; BASIC-NEXT: catch i8* null
+; BASIC-NEXT: br label [[EXIT]]
+; BASIC: Exit:
+; BASIC-NEXT: [[DOT0:%.*]] = phi i32 [ 1, [[TMP0:%.*]] ], [ 0, [[CATCH]] ]
+; BASIC-NEXT: ret i32 [[DOT0]]
+;
+; ALL-LABEL: define {{[^@]+}}@terminator
+; ALL-SAME: (i32* [[P:%.*]]) personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
+; ALL-NEXT: invoke void @may_throwv2(i32* nonnull [[P]])
+; ALL-NEXT: to label [[EXIT:%.*]] unwind label [[CATCH:%.*]]
+; ALL: Catch:
+; ALL-NEXT: [[V:%.*]] = landingpad { i8*, i32 }
+; ALL-NEXT: catch i8* null
+; ALL-NEXT: br label [[EXIT]]
+; ALL: Exit:
+; ALL-NEXT: [[DOT0:%.*]] = phi i32 [ 1, [[TMP0:%.*]] ], [ 0, [[CATCH]] ]
+; ALL-NEXT: ret i32 [[DOT0]]
+;
+; WITH-AC-LABEL: define {{[^@]+}}@terminator
+; WITH-AC-SAME: (i32* [[P:%.*]]) personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
+; WITH-AC-NEXT: invoke void @may_throwv2(i32* nonnull [[P]])
+; WITH-AC-NEXT: to label [[EXIT:%.*]] unwind label [[CATCH:%.*]]
+; WITH-AC: Catch:
+; WITH-AC-NEXT: [[V:%.*]] = landingpad { i8*, i32 }
+; WITH-AC-NEXT: catch i8* null
+; WITH-AC-NEXT: br label [[EXIT]]
+; WITH-AC: Exit:
+; WITH-AC-NEXT: [[DOT0:%.*]] = phi i32 [ 1, [[TMP0:%.*]] ], [ 0, [[CATCH]] ]
+; WITH-AC-NEXT: ret i32 [[DOT0]]
+;
+; CROSS-BLOCK-LABEL: define {{[^@]+}}@terminator
+; CROSS-BLOCK-SAME: (i32* [[P:%.*]]) personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
+; CROSS-BLOCK-NEXT: invoke void @may_throwv2(i32* nonnull [[P]])
+; CROSS-BLOCK-NEXT: to label [[EXIT:%.*]] unwind label [[CATCH:%.*]]
+; CROSS-BLOCK: Catch:
+; CROSS-BLOCK-NEXT: [[V:%.*]] = landingpad { i8*, i32 }
+; CROSS-BLOCK-NEXT: catch i8* null
+; CROSS-BLOCK-NEXT: br label [[EXIT]]
+; CROSS-BLOCK: Exit:
+; CROSS-BLOCK-NEXT: [[DOT0:%.*]] = phi i32 [ 1, [[TMP0:%.*]] ], [ 0, [[CATCH]] ]
+; CROSS-BLOCK-NEXT: ret i32 [[DOT0]]
+;
+; FULL-SIMPLIFY-LABEL: define {{[^@]+}}@terminator
+; FULL-SIMPLIFY-SAME: (i32* [[P:%.*]]) personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
+; FULL-SIMPLIFY-NEXT: invoke void @may_throwv2(i32* nonnull [[P]])
+; FULL-SIMPLIFY-NEXT: to label [[EXIT:%.*]] unwind label [[CATCH:%.*]]
+; FULL-SIMPLIFY: Catch:
+; FULL-SIMPLIFY-NEXT: [[V:%.*]] = landingpad { i8*, i32 }
+; FULL-SIMPLIFY-NEXT: catch i8* null
+; FULL-SIMPLIFY-NEXT: br label [[EXIT]]
+; FULL-SIMPLIFY: Exit:
+; FULL-SIMPLIFY-NEXT: [[DOT0:%.*]] = phi i32 [ 1, [[TMP0:%.*]] ], [ 0, [[CATCH]] ]
+; FULL-SIMPLIFY-NEXT: ret i32 [[DOT0]]
+;
+ invoke void @may_throwv2(i32* nonnull %P)
+ to label %Exit unwind label %Catch
+
+Catch: ; preds = %0
+ %v = landingpad { i8*, i32 }
+ catch i8* null
+ br label %Exit
+
+Exit: ; preds = %7, %5
+ %.0 = phi i32 [ 1, %0 ], [ 0, %Catch ]
+ ret i32 %.0
+}
+
+declare dso_local i32 @__gxx_personality_v0(...)
More information about the llvm-commits
mailing list