[PATCH] D102201: [IR][AutoUpgrade] Drop align attribute from void return types
Steven Wu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon May 10 15:26:19 PDT 2021
steven_wu created this revision.
steven_wu added reviewers: jdoerfert, fhahn, dexonsmith.
Herald added subscribers: ributzka, hiraditya.
steven_wu requested review of this revision.
Herald added a project: LLVM.
Since D87304 <https://reviews.llvm.org/D87304>, `align` become an invalid attribute on none pointer types and
verifier will reject bitcode that has invalid `align` attribute.
The problem is before the change, DeadArgumentElimination can easily
turn a pointer return type into a void return type without removing
`align` attribute. Teach Autograde to remove invalid `align` attribute
from return types to maintain bitcode compatibility.
rdar://77022993
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D102201
Files:
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/lib/IR/AutoUpgrade.cpp
llvm/test/Bitcode/upgrade-void-ret-attr.bc
llvm/test/Bitcode/upgrade-void-ret-attr.ll
Index: llvm/test/Bitcode/upgrade-void-ret-attr.ll
===================================================================
--- /dev/null
+++ llvm/test/Bitcode/upgrade-void-ret-attr.ll
@@ -0,0 +1,14 @@
+;; Check upgrade is removing the incompatible attributes on void type from old bitcode
+
+; RUN: llvm-dis < %S/upgrade-void-ret-attr.bc | FileCheck %s
+
+; CHECK: define void @f()
+define align 8 void @f() {
+ ret void
+}
+
+define void @g() {
+; CHECK: call void @f()
+ call align 8 void @f();
+ ret void
+}
Index: llvm/lib/IR/AutoUpgrade.cpp
===================================================================
--- llvm/lib/IR/AutoUpgrade.cpp
+++ llvm/lib/IR/AutoUpgrade.cpp
@@ -4371,6 +4371,12 @@
Attribute NewAttr = Attribute::getWithByValType(F.getContext(), ByValTy);
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() &&
+ F.hasAttribute(AttributeList::ReturnIndex, Attribute::Alignment))
+ F.removeAttribute(AttributeList::ReturnIndex, 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
@@ -5562,8 +5562,8 @@
}
}
- // "Upgrade" older incorrect branch weights by dropping them.
for (auto &I : instructions(F)) {
+ // "Upgrade" older incorrect branch weights by dropping them.
if (auto *MD = I.getMetadata(LLVMContext::MD_prof)) {
if (MD->getOperand(0) != nullptr && isa<MDString>(MD->getOperand(0))) {
MDString *MDS = cast<MDString>(MD->getOperand(0));
@@ -5590,6 +5590,12 @@
I.setMetadata(LLVMContext::MD_prof, nullptr);
}
}
+
+ // Remove align from return attribute on CallInst.
+ if (auto *CI = dyn_cast<CallInst>(&I)) {
+ if (CI->getFunctionType()->getReturnType()->isVoidTy())
+ CI->removeAttribute(0, Attribute::Alignment);
+ }
}
// Look for functions that rely on old function attribute behavior.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102201.344219.patch
Type: text/x-patch
Size: 2219 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210510/62969327/attachment.bin>
More information about the llvm-commits
mailing list