forked from OSchip/llvm-project
[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
This commit is contained in:
parent
d6a228cba4
commit
4eff946947
|
@ -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.
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
}
|
Binary file not shown.
Loading…
Reference in New Issue