This is an archive of the discontinued LLVM Phabricator instance.

[AMDGPU] Fix discarded result of addAttribute
ClosedPublic

Authored by modocache on Dec 7 2018, 7:09 AM.

Details

Summary

llvm::AttributeList and llvm::AttributeSet are immutable, and so methods
defined on these classes, such as addAttribute, return a new immutable
object with the attribute added. In https://reviews.llvm.org/D55217 I attempted
to annotate methods such as addAttribute with LLVM_NODISCARD, since
calling these methods has no side-effects, and so ignoring the result
that is returned is almost certainly a programmer error.

However, committing the change resulted in new warnings in the AMDGPU target.
The AMDGPU simplify libcalls pass added in https://reviews.llvm.org/D36436
attempts to add the readonly and nounwind attributes to simplified
library functions, but instead calls the addAttribute methods and
ignores the result.

Modify the simplify libcalls pass to actually add the nounwind and
readonly attributes. Also update the simplify libcalls test to assert
that these attributes are actually being set.

Diff Detail

Repository
rL LLVM

Event Timeline

modocache created this revision.Dec 7 2018, 7:09 AM
nhaehnle added inline comments.Dec 7 2018, 8:11 AM
test/CodeGen/AMDGPU/simplify-libcalls.ll
791 ↗(On Diff #177210)

Shouldn't this be #[[$NOUNWIND_READONLY]] = { nounwind readonly }? Or better yet, drop the $ - I really don't know why the existing checks have $NOUNWIND instead of just NOUNWIND.

modocache updated this revision to Diff 177427.Dec 9 2018, 7:28 AM

Thanks for the review, @nhaehnle! I changed the FileCheck variable NOUNWIND_READONLY to not use a dollar-sign prefix. I'm not sure why the other lines in this test do, but I left them alone for now. Any other suggestions for this, or is it good to go?

arsenm added a comment.Dec 9 2018, 8:13 AM

The $ is supposed to be for check variables that are used globally and not cleared on a -LABEL

modocache marked an inline comment as done.Dec 9 2018, 8:14 AM
modocache added inline comments.
test/CodeGen/AMDGPU/simplify-libcalls.ll
790 ↗(On Diff #177427)

My original diff fixed the typo in this check statement -- this should be GCN-PRELINK, not CGN-PRELINK. But in the interest of keeping this patch small and only changing one thing at a time, I've left this line alone for now. For what it's worth, the tests do pass with this typo fixed so that the CHECK is actually run.

arsenm added a comment.Dec 9 2018, 8:21 AM

The $ is supposed to be for check variables that are used globally and not cleared on a -LABEL

i.e. it's correct for this use case where the check is outside of the scope of the defining -LABEL block

modocache updated this revision to Diff 177440.EditedDec 9 2018, 9:03 AM

I see, thanks @arsenm! I think this variable fits those criteria so I changed it back to using a dollar-sign prefix. Variable names notwithstanding, does the implementation change seem OK to everyone? It fixes what I believe is clearly a programming error. Landing this change will unblock me from adding LLVM_NODISCARD to these functions and so preventing another case of this same error.

rampitec accepted this revision.Dec 9 2018, 9:43 AM

LGTM

This revision is now accepted and ready to land.Dec 9 2018, 9:43 AM
This revision was automatically updated to reflect the committed changes.