[PATCH] D102726: [IR][AutoUpgrade] Drop alignment from non-pointer parameters and returns

Steven Wu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 18 14:30:12 PDT 2021


steven_wu created this revision.
steven_wu added reviewers: jdoerfert, dexonsmith, fhahn.
Herald added subscribers: ributzka, hiraditya.
steven_wu requested review of this revision.
Herald added a project: LLVM.

This is a follow-up of D102201 <https://reviews.llvm.org/D102201>. After some discussion, it is a better idea
to upgrade all invalid uses of alignment attributes on function return
values and parameters, not just limited to void function return types.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102726

Files:
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/IR/AutoUpgrade.cpp
  llvm/test/Bitcode/upgrade-align-attr-non-ptr-11.0.ll
  llvm/test/Bitcode/upgrade-align-attr-non-ptr-11.0.ll.bc


Index: llvm/test/Bitcode/upgrade-align-attr-non-ptr-11.0.ll
===================================================================
--- /dev/null
+++ llvm/test/Bitcode/upgrade-align-attr-non-ptr-11.0.ll
@@ -0,0 +1,14 @@
+; Check upgrade is removing the incompatible attributes on function types.
+
+; RUN: llvm-dis < %s.bc | FileCheck %s
+
+; CHECK: define i8 @f(i8 %0, i8 %1)
+define align 8 i8 @f(i8 align 8 %0, i8 align 8 %1) {
+  ret i8 0
+}
+
+define void @g() {
+; CHECK: call i8 @f(i8 0, i8 1)
+  %1 = call align 8 i8 @f(i8 align 8 0, i8 align 8 1);
+  ret void
+}
Index: llvm/lib/IR/AutoUpgrade.cpp
===================================================================
--- llvm/lib/IR/AutoUpgrade.cpp
+++ llvm/lib/IR/AutoUpgrade.cpp
@@ -4377,11 +4377,19 @@
     F.addParamAttr(0, NewAttr);
   }
 
-  // If function has void return type, check it has align attribute. It has no
-  // affect on the return type and no longer passes the verifier.
-  if (F.getReturnType()->isVoidTy() &&
+  // If function has non-pointer return type, check it has align attribute. It
+  // has no affect on the return type and no longer passes the verifier.
+  if (!F.getReturnType()->isPointerTy() &&
       F.hasAttribute(AttributeList::ReturnIndex, Attribute::Alignment))
     F.removeAttribute(AttributeList::ReturnIndex, Attribute::Alignment);
+
+  // Remove align attribute on non-pointer arguments.
+  for (unsigned ArgNo = 0; ArgNo < F.getFunctionType()->getNumParams();
+       ++ArgNo) {
+    if (!F.getFunctionType()->getFunctionParamType(ArgNo)->isPointerTy() &&
+        F.hasParamAttribute(ArgNo, Attribute::Alignment))
+      F.removeParamAttr(ArgNo, Attribute::Alignment);
+  }
 }
 
 static bool isOldLoopArgument(Metadata *MD) {
Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
===================================================================
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -5627,10 +5627,20 @@
       }
     }
 
-    // Remove align from return attribute on CallInst.
+    // Remove align attribute on non pointer types on CallInst.
     if (auto *CI = dyn_cast<CallInst>(&I)) {
-      if (CI->getFunctionType()->getReturnType()->isVoidTy())
+      if (!CI->getFunctionType()->getReturnType()->isPointerTy() &&
+          CI->hasRetAttr(Attribute::Alignment))
         CI->removeAttribute(0, Attribute::Alignment);
+
+      for (unsigned ArgNo = 0; ArgNo < CI->getFunctionType()->getNumParams();
+           ++ArgNo) {
+        if (!CI->getFunctionType()
+                 ->getFunctionParamType(ArgNo)
+                 ->isPointerTy() &&
+            CI->paramHasAttr(ArgNo, Attribute::Alignment))
+          CI->removeParamAttr(ArgNo, Attribute::Alignment);
+      }
     }
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102726.346272.patch
Type: text/x-patch
Size: 2751 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210518/25d2d767/attachment.bin>


More information about the llvm-commits mailing list