This is an archive of the discontinued LLVM Phabricator instance.

[AssumeBundles] Add nonnull/align to op bundle if noundef exists
ClosedPublic

Authored by aqjune on Mar 8 2021, 6:17 PM.

Details

Summary

This is a patch to add nonnull and align to assume's operand bundle
only if noundef exists.
Since nonnull and align in fn attr have poison semantics, they should be
paired with noundef or noundef-implying attributes to be immediate UB.

Diff Detail

Event Timeline

aqjune created this revision.Mar 8 2021, 6:17 PM
aqjune requested review of this revision.Mar 8 2021, 6:17 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 8 2021, 6:17 PM
aqjune added inline comments.Mar 8 2021, 6:19 PM
llvm/lib/Transforms/Utils/AssumeBundleBuilder.cpp
203–215

The new code isn't super clean compared to the previous one, but I had to pivot to iterate-per-argidx first to check existence of noundef in the callsite and called function. :(

Tyker added a comment.Mar 9 2021, 1:42 AM

I think the process of checking is a value is noundef needs to be more general than just calls. maybe addKnowledge would be a better place.
because nonnull and align information can also be inferred from loads/stores.

I think the process of checking is a value is noundef needs to be more general than just calls. maybe addKnowledge would be a better place.
because nonnull and align information can also be inferred from loads/stores.

Hi, sorry for my delay in response.
Could you elaborate a bit with an example, please?
Does it mean that the updated analysis may return suboptimal results?

jdoerfert added inline comments.Mar 15 2021, 8:35 AM
llvm/lib/Transforms/Utils/AssumeBundleBuilder.cpp
201

I think this interface must take a Use not a value. Then you can check if Attr is allowed to be transformed into an operand bundle by checking if the use has noundef as well.

aqjune updated this revision to Diff 330705.Mar 15 2021, 10:06 AM

check if the argument has noundef

jdoerfert accepted this revision.Mar 15 2021, 10:09 AM

LGTM, maybe wait a bit to see if @Tyker want's to comment.

This revision is now accepted and ready to land.Mar 15 2021, 10:09 AM
aqjune added inline comments.Mar 15 2021, 10:09 AM
llvm/lib/Transforms/Utils/AssumeBundleBuilder.cpp
201

Checking if the use (parameter) has noundef seemed great idea to me, it could shorten the code quite a bit.
Though I put the check at addCall because it already has a CallBase object and the argument index. I'm happy to move towards making WasOn Use & it it can be simplified.

Tyker accepted this revision.EditedMar 15 2021, 10:18 AM

I think the process of checking is a value is noundef needs to be more general than just calls. maybe addKnowledge would be a better place.
because nonnull and align information can also be inferred from loads/stores.

Hi, sorry for my delay in response.
Could you elaborate a bit with an example, please?
Does it mean that the updated analysis may return suboptimal results?

after further thinking, moving nonundef checking to addKnowledge is not needed since if align or nonnnull was wrong the load/store would have UB.

the code is much shorter and much more readable now.
LGTM.

Thank you all!

This revision was landed with ongoing or failed builds.Mar 15 2021, 10:23 AM
This revision was automatically updated to reflect the committed changes.