[PATCH] D51936: Fix a use-after-RAUW bug in large GEP splitting
Krzysztof Pszeniczny via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 18 18:31:36 PDT 2018
amharc updated this revision to Diff 170138.
amharc edited the summary of this revision.
amharc added a comment.
Updated the patch to manually merge vectors of large GEP offsets when doing a RAUW of an invariant.group strip/launder intrinsic. This requires only handling keys and not values of the map, as values are always `GetElementPtr` instructions and not intrinsic calls.
I do not have the necessary level of understanding of CGP to determine if there are any other RAUWs there that need attention too, but so far I wasn't able to reproduce in cases that do not relate to invariant.group strips/launders.
https://reviews.llvm.org/D51936
Files:
llvm/lib/CodeGen/CodeGenPrepare.cpp
llvm/test/Transforms/CodeGenPrepare/AArch64/large-offset-gep.ll
Index: llvm/test/Transforms/CodeGenPrepare/AArch64/large-offset-gep.ll
===================================================================
--- llvm/test/Transforms/CodeGenPrepare/AArch64/large-offset-gep.ll
+++ llvm/test/Transforms/CodeGenPrepare/AArch64/large-offset-gep.ll
@@ -145,3 +145,31 @@
while_end:
ret void
}
+
+declare i8* @llvm.strip.invariant.group.p0i8(i8*)
+
+define void @test_invariant_group(i32) {
+; CHECK-LABEL: test_invariant_group
+ br i1 undef, label %8, label %7
+
+; <label>:2: ; preds = %8, %2
+ br i1 undef, label %2, label %7
+
+; <label>:3: ; preds = %8
+ %4 = getelementptr inbounds i8, i8* %9, i32 40000
+ %5 = bitcast i8* %4 to i64*
+ br i1 undef, label %7, label %6
+
+; <label>:6: ; preds = %3
+ store i64 1, i64* %5, align 8
+ br label %7
+
+; <label>:7: ; preds = %6, %3, %2, %1
+ ret void
+
+; <label>:8: ; preds = %1
+ %9 = call i8* @llvm.strip.invariant.group.p0i8(i8* nonnull undef)
+ %10 = icmp eq i32 %0, 0
+ br i1 %10, label %3, label %2
+}
+
Index: llvm/lib/CodeGen/CodeGenPrepare.cpp
===================================================================
--- llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -1721,11 +1721,22 @@
return true;
}
case Intrinsic::launder_invariant_group:
- case Intrinsic::strip_invariant_group:
- II->replaceAllUsesWith(II->getArgOperand(0));
+ case Intrinsic::strip_invariant_group: {
+ Value *ArgVal = II->getArgOperand(0);
+ auto it = LargeOffsetGEPMap.find(II);
+ if (it != LargeOffsetGEPMap.end()) {
+ // Merge entries in LargeOffsetGEPMap to reflect the RAUW.
+ // Make sure not to have to deal with iterator invalidation
+ // after possibly adding ArgVal to LargeOffsetGEPMap.
+ auto GEPs = std::move(it->second);
+ LargeOffsetGEPMap[ArgVal].append(GEPs.begin(), GEPs.end());
+ LargeOffsetGEPMap.erase(II);
+ }
+
+ II->replaceAllUsesWith(ArgVal);
II->eraseFromParent();
return true;
-
+ }
case Intrinsic::cttz:
case Intrinsic::ctlz:
// If counting zeros is expensive, try to avoid it.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51936.170138.patch
Type: text/x-patch
Size: 2336 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181019/4d5f903d/attachment-0001.bin>
More information about the llvm-commits
mailing list