Skip to content

Commit be0a3b2

Browse files
authored
[IR] Allow llvm.experimental.memset.pattern to take any sized type as the pattern argument (#132026)
I initially thought starting with a more narrow definition and later expanding would make more sense. But as pointed out in review for PR #129220, this restriction is generating additional unnecessary work. This patch alters the intrinsic to accept patterns of any type. Future patches will update LoopIdiomRecognize and PreISelIntrinsicLowering to take advantage of this. The verifier will complain if an unsized type is used. I've additionally taken the opportunity to remove a comment from the LangRef about some bit widths potentially not being supported by the target. I don't think this is any more true than it is for arbitrary width loads/stores which don't carry a similar warning that I can see. A verifier check ensures that only sized types are used for the pattern.
1 parent baef6fa commit be0a3b2

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

llvm/docs/LangRef.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15640,8 +15640,8 @@ Syntax:
1564015640
"""""""
1564115641

1564215642
This is an overloaded intrinsic. You can use
15643-
``llvm.experimental.memset.pattern`` on any integer bit width and for
15644-
different address spaces. Not all targets support all bit widths however.
15643+
``llvm.experimental.memset.pattern`` on any sized type and for different
15644+
address spaces.
1564515645

1564615646
::
1564715647

llvm/include/llvm/IR/Intrinsics.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ def int_memset_inline
10251025
def int_experimental_memset_pattern
10261026
: Intrinsic<[],
10271027
[llvm_anyptr_ty, // Destination.
1028-
llvm_anyint_ty, // Pattern value.
1028+
llvm_any_ty, // Pattern value.
10291029
llvm_anyint_ty, // Count (number of times to fill value).
10301030
llvm_i1_ty], // IsVolatile.
10311031
[IntrWriteMem, IntrArgMemOnly, IntrWillReturn, IntrNoFree, IntrNoCallback,

llvm/lib/IR/Verifier.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5583,7 +5583,11 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
55835583
case Intrinsic::memmove:
55845584
case Intrinsic::memset:
55855585
case Intrinsic::memset_inline:
5586+
break;
55865587
case Intrinsic::experimental_memset_pattern: {
5588+
const auto Memset = cast<MemSetPatternInst>(&Call);
5589+
Check(Memset->getValue()->getType()->isSized(),
5590+
"unsized types cannot be used as memset patterns", Call);
55875591
break;
55885592
}
55895593
case Intrinsic::memcpy_element_unordered_atomic:
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
; RUN: not opt -passes=verify < %s 2>&1 | FileCheck %s
2+
3+
; CHECK: unsized types cannot be used as memset patterns
4+
5+
%X = type opaque
6+
define void @bar(ptr %P, %X %value) {
7+
call void @llvm.experimental.memset.pattern.p0.s_s.i32.0(ptr %P, %X %value, i32 4, i1 false)
8+
ret void
9+
}
10+
declare void @llvm.experimental.memset.pattern.p0.s_s.i32.0(ptr nocapture, %X, i32, i1) nounwind

0 commit comments

Comments
 (0)