[PATCH] D102110: [Inliner] Fix noalias metadata handling for instructions simplified during cloning (PR50270)
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue May 18 12:01:43 PDT 2021
nikic added inline comments.
================
Comment at: llvm/lib/Transforms/Utils/InlineFunction.cpp:997
// instructions, add the alias scope metadata.
for (ValueToValueMapTy::iterator VMI = VMap.begin(), VMIE = VMap.end();
VMI != VMIE; ++VMI) {
----------------
jeroen.dobbelaere wrote:
> Just wondering: don't we have a similar issue here ?
Yes, unfortunately we do. It took me a while, but I found a suitable `llvm.masked.load` fold to exploit:
```
define <2 x i8> @callee(<2 x i8>* %ptr1, <2 x i8>* noalias %ptr2, <2 x i1> %mask, <2 x i8> %passthru) {
%ret = call <2 x i8> @llvm.masked.load.v2i8(<2 x i8>* %ptr1, i32 1, <2 x i1> %mask, <2 x i8> %passthru)
store <2 x i8> zeroinitializer, <2 x i8>* %ptr2
ret <2 x i8> %ret
}
define void @caller(<2 x i8>* %ptr1, <2 x i8>* %ptr2) {
%passthru = load <2 x i8>, <2 x i8>* %ptr2
call <2 x i8> @callee(<2 x i8>* %ptr1, <2 x i8>* %ptr2, <2 x i1> zeroinitializer, <2 x i8> %passthru)
ret void
}
declare <2 x i8> @llvm.masked.load.v2i8(<2 x i8>*, i32, <2 x i1>, <2 x i8>)
```
Results in:
```
define <2 x i8> @callee(<2 x i8>* %ptr1, <2 x i8>* noalias %ptr2, <2 x i1> %mask, <2 x i8> %passthru) {
%ret = call <2 x i8> @llvm.masked.load.v2i8.p0v2i8(<2 x i8>* %ptr1, i32 1, <2 x i1> %mask, <2 x i8> %passthru)
store <2 x i8> zeroinitializer, <2 x i8>* %ptr2, align 2
ret <2 x i8> %ret
}
define void @caller(<2 x i8>* %ptr1, <2 x i8>* %ptr2) {
%passthru = load <2 x i8>, <2 x i8>* %ptr2, align 2, !noalias !0
call void @llvm.experimental.noalias.scope.decl(metadata !0)
store <2 x i8> zeroinitializer, <2 x i8>* %ptr2, align 2, !alias.scope !0
ret void
}
```
In this case, we don't even need the incorrect annotation to go on an instruction from the caller, it can also happen with a callee instruction:
```
define <2 x i8> @callee(<2 x i8>* %ptr1, <2 x i8>* noalias %ptr2, <2 x i1> %mask) {
%passthru = load <2 x i8>, <2 x i8>* %ptr2
%ret = call <2 x i8> @llvm.masked.load.v2i8(<2 x i8>* %ptr1, i32 1, <2 x i1> %mask, <2 x i8> %passthru)
store <2 x i8> zeroinitializer, <2 x i8>* %ptr2
ret <2 x i8> %ret
}
define void @caller(<2 x i8>* %ptr1, <2 x i8>* %ptr2) {
call <2 x i8> @callee(<2 x i8>* %ptr1, <2 x i8>* %ptr2, <2 x i1> zeroinitializer)
ret void
}
declare <2 x i8> @llvm.masked.load.v2i8(<2 x i8>*, i32, <2 x i1>, <2 x i8>)
```
Results in:
```
define <2 x i8> @callee(<2 x i8>* %ptr1, <2 x i8>* noalias %ptr2, <2 x i1> %mask) {
%passthru = load <2 x i8>, <2 x i8>* %ptr2, align 2
%ret = call <2 x i8> @llvm.masked.load.v2i8.p0v2i8(<2 x i8>* %ptr1, i32 1, <2 x i1> %mask, <2 x i8> %passthru)
store <2 x i8> zeroinitializer, <2 x i8>* %ptr2, align 2
ret <2 x i8> %ret
}
define void @caller(<2 x i8>* %ptr1, <2 x i8>* %ptr2) {
call void @llvm.experimental.noalias.scope.decl(metadata !0)
%passthru.i = load <2 x i8>, <2 x i8>* %ptr2, align 2, !alias.scope !0, !noalias !0
store <2 x i8> zeroinitializer, <2 x i8>* %ptr2, align 2, !alias.scope !0
ret void
}
```
Note how the metadata is claiming that the load does not alias ... with itself.
So, in this case the problem is a bit different from the other two: We have to not just prevent annotating instructions from the caller, we should prevent annotating //any// instructions for which some kind of folding occurred.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D102110/new/
https://reviews.llvm.org/D102110
More information about the llvm-commits
mailing list