This is an archive of the discontinued LLVM Phabricator instance.

[IR][RFC] Restrict read only when cache type of llvm.prefetch is instruction
Needs ReviewPublic

Authored by pengfei on Oct 18 2022, 2:16 AM.

Details

Summary

LLVM backends like X86 always lowers prefetch intrinsics into similar
type if the desired one is not available.
For example, T2 hint -> T1 or write hint -> read. See llvm/test/CodeGen/X86/prefetch.ll
However, it's not clear for backend to choose between "write data" or "read
instruction" if there is no native "write instruction" instructions.
As far as I know, there's no upstream target that has supported "write
instruction" at the moment. So there should be no real impact by this
patch.

Diff Detail

Event Timeline

pengfei created this revision.Oct 18 2022, 2:16 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 18 2022, 2:16 AM
pengfei requested review of this revision.Oct 18 2022, 2:16 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptOct 18 2022, 2:16 AM

The Arm changes (for tests) here are reasonable, and indeed both arm architectures do not allocate encoding space for instruction write.

The Arm changes (for tests) here are reasonable, and indeed both arm architectures do not allocate encoding space for instruction write.

Thanks @lenary for confirmation!

uweigand added inline comments.Oct 18 2022, 4:06 AM
llvm/test/CodeGen/SystemZ/prefetch-01.ll
17–18

If we decide to declare this invalid, then I'd prefer to remove the test instead of commenting it out.

pengfei updated this revision to Diff 468486.Oct 18 2022, 4:55 AM
pengfei marked an inline comment as done.

Remove instruction write prefetch test from SystemZ.

craig.topper added inline comments.Oct 18 2022, 8:47 PM
clang/lib/Sema/SemaChecking.cpp
7574

Not clear to me that we should be changing the definition of __builtin_prefetch.

It wouldn't cost much to add a new builtin for X86 for the new instructions.

craig.topper added inline comments.Oct 18 2022, 8:49 PM
clang/lib/Sema/SemaChecking.cpp
7574

It definitely shouldn't be buried in this patch the way it is currently titled and described.

pengfei added inline comments.Oct 19 2022, 1:23 AM
clang/lib/Sema/SemaChecking.cpp
7574

Sure, I have added a new builtin in D136040. But I don't see any concerns for this patch so far.

Matt added a subscriber: Matt.Oct 19 2022, 5:13 PM
arsenm added a subscriber: arsenm.Oct 19 2022, 6:55 PM
arsenm added inline comments.
llvm/lib/IR/Verifier.cpp
5180

Should add new verifier tests for this.

Also, if this requires any auto upgrade, I would appreciate adding address space mangling to the intrinsic at the same time