[llvm] 4eff946 - [IR][AutoUpgrade] Drop align attribute from void return types
Steven Wu via llvm-commits
llvm-commits at lists.llvm.org
Tue May 11 08:24:04 PDT 2021
Author: Steven Wu
Date: 2021-05-11T08:23:55-07:00
New Revision: 4eff9469475384a59a9da407e78aa00262edcdd0
URL: https://github.com/llvm/llvm-project/commit/4eff9469475384a59a9da407e78aa00262edcdd0
DIFF: https://github.com/llvm/llvm-project/commit/4eff9469475384a59a9da407e78aa00262edcdd0.diff
LOG: [IR][AutoUpgrade] Drop align attribute from void return types
Since 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
Reviewed By: dexonsmith
Differential Revision: https://reviews.llvm.org/D102201
Added:
llvm/test/Bitcode/upgrade-void-ret-attr-11.0.ll
llvm/test/Bitcode/upgrade-void-ret-attr-11.0.ll.bc
Modified:
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/lib/IR/AutoUpgrade.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 46db3edcc3427..38d7b77d9cfeb 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -5562,8 +5562,8 @@ Error BitcodeReader::materialize(GlobalValue *GV) {
}
}
- // "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 @@ Error BitcodeReader::materialize(GlobalValue *GV) {
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.
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index 5cef5816f2ed5..9a33645d017b7 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -4371,6 +4371,12 @@ void llvm::UpgradeFunctionAttributes(Function &F) {
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) {
diff --git a/llvm/test/Bitcode/upgrade-void-ret-attr-11.0.ll b/llvm/test/Bitcode/upgrade-void-ret-attr-11.0.ll
new file mode 100644
index 0000000000000..81852da7ce4a5
--- /dev/null
+++ b/llvm/test/Bitcode/upgrade-void-ret-attr-11.0.ll
@@ -0,0 +1,14 @@
+; Check upgrade is removing the incompatible attributes on void return type.
+
+; RUN: llvm-dis < %s.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
+}
diff --git a/llvm/test/Bitcode/upgrade-void-ret-attr-11.0.ll.bc b/llvm/test/Bitcode/upgrade-void-ret-attr-11.0.ll.bc
new file mode 100644
index 0000000000000..8e23fbe17928f
Binary files /dev/null and b/llvm/test/Bitcode/upgrade-void-ret-attr-11.0.ll.bc
diff er
More information about the llvm-commits
mailing list