[PATCH] D124173: [InstCombine] Remove memset of undef value
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 29 05:51:37 PDT 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1881711fbb7b: [InstCombine] Remove memset of undef value (authored by nikic).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D124173/new/
https://reviews.llvm.org/D124173
Files:
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
llvm/test/Transforms/InstCombine/memset.ll
llvm/test/Transforms/InstCombine/store.ll
Index: llvm/test/Transforms/InstCombine/store.ll
===================================================================
--- llvm/test/Transforms/InstCombine/store.ll
+++ llvm/test/Transforms/InstCombine/store.ll
@@ -1,6 +1,8 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -passes=instcombine -S | FileCheck %s
+; FIXME: This is technically incorrect because it might overwrite a poison
+; value. Stop folding it once #52930 is resolved.
define void @store_of_undef(i32* %P) {
; CHECK-LABEL: @store_of_undef(
; CHECK-NEXT: ret void
Index: llvm/test/Transforms/InstCombine/memset.ll
===================================================================
--- llvm/test/Transforms/InstCombine/memset.ll
+++ llvm/test/Transforms/InstCombine/memset.ll
@@ -33,9 +33,10 @@
ret void
}
+; FIXME: This is technically incorrect because it might overwrite a poison
+; value. Stop folding it once #52930 is resolved.
define void @memset_undef(i8* %p) {
; CHECK-LABEL: @memset_undef(
-; CHECK-NEXT: call void @llvm.memset.p0i8.i32(i8* noundef nonnull align 1 dereferenceable(8) [[P:%.*]], i8 undef, i32 8, i1 false)
; CHECK-NEXT: ret void
;
call void @llvm.memset.p0i8.i32(i8* %p, i8 undef, i32 8, i1 false)
@@ -53,7 +54,6 @@
define void @memset_poison(i8* %p) {
; CHECK-LABEL: @memset_poison(
-; CHECK-NEXT: call void @llvm.memset.p0i8.i32(i8* noundef nonnull align 1 dereferenceable(8) [[P:%.*]], i8 poison, i32 8, i1 false)
; CHECK-NEXT: ret void
;
call void @llvm.memset.p0i8.i32(i8* %p, i8 poison, i32 8, i1 false)
Index: llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
@@ -1435,6 +1435,8 @@
}
// store undef, Ptr -> noop
+ // FIXME: This is technically incorrect because it might overwrite a poison
+ // value. Change to PoisonValue once #52930 is resolved.
if (isa<UndefValue>(Val))
return eraseInstFromFunction(SI);
Index: llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -258,6 +258,15 @@
return MI;
}
+ // Remove memset with an undef value.
+ // FIXME: This is technically incorrect because it might overwrite a poison
+ // value. Change to PoisonValue once #52930 is resolved.
+ if (isa<UndefValue>(MI->getValue())) {
+ // Set the size of the copy to 0, it will be deleted on the next iteration.
+ MI->setLength(Constant::getNullValue(MI->getLength()->getType()));
+ return MI;
+ }
+
// Extract the length and alignment and fill if they are constant.
ConstantInt *LenC = dyn_cast<ConstantInt>(MI->getLength());
ConstantInt *FillC = dyn_cast<ConstantInt>(MI->getValue());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124173.426029.patch
Type: text/x-patch
Size: 3010 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220429/fd7df2f4/attachment.bin>
More information about the llvm-commits
mailing list