[PATCH] D55435: [AMDGPU] Fix discarded result of addAttribute

Brian Gesiak via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 7 07:10:03 PST 2018


modocache created this revision.
modocache added reviewers: rampitec, vpykhtin, rnk.
Herald added subscribers: t-tye, tpr, dstuttard, yaxunl, nhaehnle, wdng, jvesely, kzhuravl, arsenm.

`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.


Repository:
  rL LLVM

https://reviews.llvm.org/D55435

Files:
  lib/Target/AMDGPU/AMDGPULibFunc.cpp
  test/CodeGen/AMDGPU/simplify-libcalls.ll


Index: test/CodeGen/AMDGPU/simplify-libcalls.ll
===================================================================
--- test/CodeGen/AMDGPU/simplify-libcalls.ll
+++ test/CodeGen/AMDGPU/simplify-libcalls.ll
@@ -783,5 +783,10 @@
   ret void
 }
 
-; CGN-PRELINK: attributes #[[$NOUNWIND]] = { nounwind }
+; 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]]
+
+; GCN-PRELINK: attributes #[[$NOUNWIND]] = { nounwind }
+; GCN-PRELINK: attributes #{{[0-9]+}} = { nounwind readonly }
 attributes #0 = { nounwind }
Index: lib/Target/AMDGPU/AMDGPULibFunc.cpp
===================================================================
--- lib/Target/AMDGPU/AMDGPULibFunc.cpp
+++ lib/Target/AMDGPU/AMDGPULibFunc.cpp
@@ -995,8 +995,10 @@
   } 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);
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55435.177210.patch
Type: text/x-patch
Size: 1486 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181207/d6c68f54/attachment.bin>


More information about the llvm-commits mailing list