[PATCH] D86157: [DeadArgElim][FIX] Drop more attributes when the return type changes

Johannes Doerfert via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 18 10:47:00 PDT 2020


jdoerfert created this revision.
jdoerfert added reviewers: fhahn, lebedev.ri, spatel.
Herald added subscribers: bollu, hiraditya.
Herald added a project: LLVM.
jdoerfert requested review of this revision.

We should not have `align` or `noundef` on `void` return types.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86157

Files:
  llvm/lib/IR/Attributes.cpp
  llvm/test/Transforms/DeadArgElim/returned.ll


Index: llvm/test/Transforms/DeadArgElim/returned.ll
===================================================================
--- llvm/test/Transforms/DeadArgElim/returned.ll
+++ llvm/test/Transforms/DeadArgElim/returned.ll
@@ -43,6 +43,12 @@
   ret %Ty* %this
 }
 
+; Drop all these attributes
+; CHECK-LABEL: define internal void @test6
+define internal align 8 dereferenceable_or_null(2) noundef noalias i8* @test6() {
+  ret i8* null
+}
+
 define %Ty* @caller(%Ty* %this) {
   %1 = call %Ty* @test1(%Ty* %this)
   %2 = call %Ty* @test2(%Ty* %this)
@@ -51,5 +57,6 @@
 ; ...instead, drop 'returned' form the call site
 ; CHECK: call void @test5(%Ty* %this)
   %5 = call %Ty* @test5(%Ty* returned %this)
+  %6 = call i8* @test6()
   ret %Ty* %this
 }
Index: llvm/lib/IR/Attributes.cpp
===================================================================
--- llvm/lib/IR/Attributes.cpp
+++ llvm/lib/IR/Attributes.cpp
@@ -1856,6 +1856,7 @@
         .addAttribute(Attribute::NoAlias)
         .addAttribute(Attribute::NoCapture)
         .addAttribute(Attribute::NonNull)
+        .addAlignmentAttr(1)             // the int here is ignored
         .addDereferenceableAttr(1)       // the int here is ignored
         .addDereferenceableOrNullAttr(1) // the int here is ignored
         .addAttribute(Attribute::ReadNone)
@@ -1866,6 +1867,10 @@
         .addByValAttr(Ty)
         .addByRefAttr(Ty);
 
+  // Some attributes can apply to all "values" but there are no `void` values.
+  if (Ty->isVoidTy())
+    Incompatible.addAttribute(Attribute::NoUndef);
+
   return Incompatible;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86157.286351.patch
Type: text/x-patch
Size: 1580 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200818/cbc25133/attachment.bin>


More information about the llvm-commits mailing list