This is an archive of the discontinued LLVM Phabricator instance.

[InstSimplify] Add some basic simplifications for `llvm.ptrmask`
AbandonedPublic

Authored by goldstein.w.n on Jul 30 2023, 4:00 PM.

Details

Summary

Mostly the same as and. We also have a check for a useless
llvm.ptrmask if the ptr is already known aligned.

Diff Detail

Event Timeline

goldstein.w.n created this revision.Jul 30 2023, 4:00 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 30 2023, 4:00 PM
goldstein.w.n requested review of this revision.Jul 30 2023, 4:00 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 30 2023, 4:00 PM
nikic added inline comments.Jul 31 2023, 1:48 AM
llvm/test/Transforms/InstSimplify/ptrmask.ll
28

I don't think this fold is correct, but alive2 accepts it. I've filed https://github.com/AliveToolkit/alive2/issues/929.

goldstein.w.n added inline comments.Aug 1 2023, 12:47 AM
llvm/test/Transforms/InstSimplify/ptrmask.ll
28

Oh, in that case a lot of this series is out the window.
Would have thought ptr -> null would be okay, but clearly need to read up on provenance.

No need to review the rest of the series as this was assumed in A LOT of places, will refactor.

goldstein.w.n added inline comments.Aug 1 2023, 10:20 AM
llvm/test/Transforms/InstSimplify/ptrmask.ll
28

Is there a way to do this simplification w.o breaking provenance? Or do all the null returns need to be properly removed?

goldstein.w.n added inline comments.Aug 1 2023, 10:30 AM
llvm/test/Transforms/InstSimplify/ptrmask.ll
28

Would the following be acceptable?
https://alive2.llvm.org/ce/z/yMmP6J
I.e outside of lets say load/store/inttoptr/inbounds-GEP replacing %p -> null?
AFAICT those are the only operations that meaningfully interact with provenance.

goldstein.w.n added inline comments.Aug 1 2023, 11:56 AM
llvm/test/Transforms/InstSimplify/ptrmask.ll
28

Does this being illegal imply that we don't need this nullness check here: https://github.com/llvm/llvm-project/blob/main/llvm/lib/Analysis/ValueTracking.cpp#L5789

arichardson added inline comments.Aug 9 2023, 8:23 AM
llvm/test/Transforms/InstSimplify/ptrmask.ll
28

Folding these to null could definitely result in miscompilations for CHERI targets such as Morello since pointers include bounds metadata. It is possible to have a pointer with e.g. full address space bounds. If I mask that with zero I'd want a dereference able pointer that still has those bounds rather than null which is non-dereferenceable. I could imagine this kind of pattern coming up followed by some more pointer arithmetic which would be equivalent to %p with address=X (there is no such intrinsic in upstream LLVM, but the CHERI fork adds one that retains provenance and just updated the pointed-to address).

nikic added a comment.Sep 25 2023, 2:01 PM

Can you please mark this patch series as abandoned, as it has been move to GitHub?

goldstein.w.n abandoned this revision.Sep 27 2023, 10:19 AM

This has been ported to github PR.