[PATCH] D76215: [InstCombine] Transform to undef incorrect atomic unordered mem intrinsics
Serguei Katkov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 16 20:44:51 PDT 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rG80c351cdb6ea: [InstCombine] Transform to undef incorrect atomic unordered mem intrinsics (authored by skatkov).
Herald added a project: LLVM.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D76215/new/
https://reviews.llvm.org/D76215
Files:
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/test/Transforms/InstCombine/element-atomic-memintrins.ll
Index: llvm/test/Transforms/InstCombine/element-atomic-memintrins.ll
===================================================================
--- llvm/test/Transforms/InstCombine/element-atomic-memintrins.ll
+++ llvm/test/Transforms/InstCombine/element-atomic-memintrins.ll
@@ -415,4 +415,23 @@
ret void
}
+define void @test_undefined(i8* %dest, i8* %src) {
+; CHECK-LABEL: @test_undefined(
+entry:
+ br i1 undef, label %ok, label %undefined
+undefined:
+; CHECK: undefined:
+; CHECK-NEXT: store i1 true, i1* undef
+; CHECK-NEXT: br label %ok
+ call void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i32(i8* align 16 %dest, i8* align 16 %src, i32 7, i32 4)
+ call void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i32(i8* align 16 %dest, i8* align 16 %src, i32 -8, i32 4)
+ call void @llvm.memmove.element.unordered.atomic.p0i8.p0i8.i32(i8* align 16 %dest, i8* align 16 %src, i32 7, i32 4)
+ call void @llvm.memmove.element.unordered.atomic.p0i8.p0i8.i32(i8* align 16 %dest, i8* align 16 %src, i32 -8, i32 4)
+ call void @llvm.memset.element.unordered.atomic.p0i8.i32(i8* align 16 %dest, i8 1, i32 7, i32 4)
+ call void @llvm.memset.element.unordered.atomic.p0i8.i32(i8* align 16 %dest, i8 1, i32 -8, i32 4)
+ br label %ok
+ok:
+ ret void
+}
+
declare void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i32(i8* nocapture writeonly, i8* nocapture readonly, i32, i32) nounwind argmemonly
Index: llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -1806,6 +1806,18 @@
IntrinsicInst *II = dyn_cast<IntrinsicInst>(&CI);
if (!II) return visitCallBase(CI);
+ // For atomic unordered mem intrinsics if len is not a positive or
+ // not a multiple of element size then behavior is undefined.
+ if (auto *AMI = dyn_cast<AtomicMemIntrinsic>(II))
+ if (ConstantInt *NumBytes = dyn_cast<ConstantInt>(AMI->getLength()))
+ if (NumBytes->getSExtValue() < 0 ||
+ (NumBytes->getZExtValue() % AMI->getElementSizeInBytes() != 0)) {
+ CreateNonTerminatorUnreachable(AMI);
+ assert(AMI->getType()->isVoidTy() &&
+ "non void atomic unordered mem intrinsic");
+ return eraseInstFromFunction(*AMI);
+ }
+
// Intrinsics cannot occur in an invoke or a callbr, so handle them here
// instead of in visitCallBase.
if (auto *MI = dyn_cast<AnyMemIntrinsic>(II)) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76215.250686.patch
Type: text/x-patch
Size: 2521 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200317/6bc3e148/attachment.bin>
More information about the llvm-commits
mailing list