[llvm] r348732 - [AMDGPU] Fix discarded result of addAttribute
Brian Gesiak via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 9 13:56:51 PST 2018
Author: modocache
Date: Sun Dec 9 13:56:50 2018
New Revision: 348732
URL: http://llvm.org/viewvc/llvm-project?rev=348732&view=rev
Log:
[AMDGPU] Fix discarded result of addAttribute
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.
Reviewers: rampitec, vpykhtin, rnk
Reviewed By: rampitec
Subscribers: arsenm, kzhuravl, jvesely, wdng, nhaehnle, yaxunl, dstuttard, tpr, t-tye, llvm-commits
Differential Revision: https://reviews.llvm.org/D55435
Modified:
llvm/trunk/lib/Target/AMDGPU/AMDGPULibFunc.cpp
llvm/trunk/test/CodeGen/AMDGPU/simplify-libcalls.ll
Modified: llvm/trunk/lib/Target/AMDGPU/AMDGPULibFunc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AMDGPU/AMDGPULibFunc.cpp?rev=348732&r1=348731&r2=348732&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AMDGPU/AMDGPULibFunc.cpp (original)
+++ llvm/trunk/lib/Target/AMDGPU/AMDGPULibFunc.cpp Sun Dec 9 13:56:50 2018
@@ -995,8 +995,10 @@ Function *AMDGPULibFunc::getOrInsertFunc
} else {
AttributeList Attr;
LLVMContext &Ctx = M->getContext();
- Attr.addAttribute(Ctx, AttributeList::FunctionIndex, Attribute::ReadOnly);
- Attr.addAttribute(Ctx, AttributeList::FunctionIndex, Attribute::NoUnwind);
+ Attr = Attr.addAttribute(Ctx, AttributeList::FunctionIndex,
+ Attribute::ReadOnly);
+ Attr = Attr.addAttribute(Ctx, AttributeList::FunctionIndex,
+ Attribute::NoUnwind);
C = M->getOrInsertFunction(FuncName, FuncTy, Attr);
}
Modified: llvm/trunk/test/CodeGen/AMDGPU/simplify-libcalls.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AMDGPU/simplify-libcalls.ll?rev=348732&r1=348731&r2=348732&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AMDGPU/simplify-libcalls.ll (original)
+++ llvm/trunk/test/CodeGen/AMDGPU/simplify-libcalls.ll Sun Dec 9 13:56:50 2018
@@ -783,5 +783,10 @@ entry:
ret void
}
+; GCN-PRELINK: declare float @_Z4fabsf(float) local_unnamed_addr #[[$NOUNWIND_READONLY:[0-9]+]]
+; GCN-PRELINK: declare float @_Z4cbrtf(float) local_unnamed_addr #[[$NOUNWIND_READONLY]]
+; GCN-PRELINK: declare float @_Z11native_sqrtf(float) local_unnamed_addr #[[$NOUNWIND_READONLY]]
+
; CGN-PRELINK: attributes #[[$NOUNWIND]] = { nounwind }
+; GCN-PRELINK: attributes #[[$NOUNWIND_READONLY]] = { nounwind readonly }
attributes #0 = { nounwind }
More information about the llvm-commits
mailing list