This is an archive of the discontinued LLVM Phabricator instance.

The result of a function with noundef return attribute must be well defined
ClosedPublic

Authored by reames on Oct 5 2021, 1:36 PM.

Details

Summary

This does for readability of returns within said function as what we do for the caller side when reasoning about what might be poison.

Couldn't figure out a small test. I'm working on this from SCEV, but that's blocked by other things as well.

Diff Detail

Event Timeline

reames created this revision.Oct 5 2021, 1:36 PM
reames requested review of this revision.Oct 5 2021, 1:36 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 5 2021, 1:36 PM
nikic added a reviewer: nikic.Oct 5 2021, 1:46 PM
nikic added a subscriber: nikic.

If nothing else you could add a unit test, see programUndefinedIfPoison/isGuaranteedNotToBePoison tests in ValueTrackingTest.

llvm/lib/Analysis/ValueTracking.cpp
5423

This should guard against void returns, in which case getOperand(0) would assert.

nikic added inline comments.Oct 5 2021, 2:17 PM
llvm/lib/Analysis/ValueTracking.cpp
5423

Hm, I guess this is not strictly necessary thanks to https://github.com/llvm/llvm-project/blob/7d541eb4d49aaaab6a51a3568b9214fd8691e2d3/llvm/lib/IR/Attributes.cpp#L1840. Having noundef implies that the return type cannot be void.

reames planned changes to this revision.Oct 5 2021, 3:04 PM

Added D111186 as a dependency. Will rebase over updated tests once I can exercise this from SCEV.

reames updated this revision to Diff 377622.Oct 6 2021, 11:34 AM

Add tests - key detail is that removing udiv no-longer has any effect as noimplicit defs serves as a immediate UB root.

This revision is now accepted and ready to land.Oct 6 2021, 11:39 AM
This revision was landed with ongoing or failed builds.Oct 6 2021, 11:52 AM
This revision was automatically updated to reflect the committed changes.