[llvm] f14495d - [SROA] avoid crash on memset with constant expression length
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 21 12:39:22 PDT 2021
Author: Sanjay Patel
Date: 2021-07-21T15:20:28-04:00
New Revision: f14495dc75d72d8900b3f4056a36a1ba5063e957
URL: https://github.com/llvm/llvm-project/commit/f14495dc75d72d8900b3f4056a36a1ba5063e957
DIFF: https://github.com/llvm/llvm-project/commit/f14495dc75d72d8900b3f4056a36a1ba5063e957.diff
LOG: [SROA] avoid crash on memset with constant expression length
https://llvm.org/PR50888
Added:
Modified:
llvm/lib/Transforms/Scalar/SROA.cpp
llvm/test/Transforms/SROA/slice-width.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/SROA.cpp b/llvm/lib/Transforms/Scalar/SROA.cpp
index 61c8d53519be4..5ec01454e5b2f 100644
--- a/llvm/lib/Transforms/Scalar/SROA.cpp
+++ b/llvm/lib/Transforms/Scalar/SROA.cpp
@@ -2789,7 +2789,7 @@ class llvm::sroa::AllocaSliceRewriter
// If the memset has a variable size, it cannot be split, just adjust the
// pointer to the new alloca.
- if (!isa<Constant>(II.getLength())) {
+ if (!isa<ConstantInt>(II.getLength())) {
assert(!IsSplit);
assert(NewBeginOffset == BeginOffset);
II.setDest(getNewAllocaSlicePtr(IRB, OldPtr->getType()));
diff --git a/llvm/test/Transforms/SROA/slice-width.ll b/llvm/test/Transforms/SROA/slice-width.ll
index 2deef736de258..a801de68217ff 100644
--- a/llvm/test/Transforms/SROA/slice-width.ll
+++ b/llvm/test/Transforms/SROA/slice-width.ll
@@ -4,6 +4,7 @@ target datalayout = "e-p:64:64:64-p1:16:16:16-i1:8:8-i8:8:8-i16:16:16-i32:32:32-
declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i1) nounwind
declare void @llvm.memset.p0i8.i32(i8* nocapture, i8, i32, i1) nounwind
+declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i1) nounwind
; This tests that allocas are not split into slices that are not byte width multiple
define void @no_split_on_non_byte_width(i32) {
@@ -131,3 +132,16 @@ entry:
%result = call i32 @memcpy_vec3float_helper(%S.vec3float* %tmp2)
ret i32 %result
}
+
+; Don't crash on length that is constant expression.
+
+define void @PR50888() {
+; CHECK-LABEL: @PR50888(
+; CHECK-NEXT: [[ARRAY:%.*]] = alloca i8, align 1
+; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* align 1 [[ARRAY]], i8 0, i64 ptrtoint (void ()* @PR50888 to i64), i1 false)
+; CHECK-NEXT: ret void
+;
+ %array = alloca i8
+ call void @llvm.memset.p0i8.i64(i8* align 16 %array, i8 0, i64 ptrtoint (void ()* @PR50888 to i64), i1 false)
+ ret void
+}
More information about the llvm-commits
mailing list