Skip to content

Commit 4eff946

Browse files
[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
1 parent d6a228c commit 4eff946

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

llvm/lib/Bitcode/Reader/BitcodeReader.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5562,8 +5562,8 @@ Error BitcodeReader::materialize(GlobalValue *GV) {
55625562
}
55635563
}
55645564

5565-
// "Upgrade" older incorrect branch weights by dropping them.
55665565
for (auto &I : instructions(F)) {
5566+
// "Upgrade" older incorrect branch weights by dropping them.
55675567
if (auto *MD = I.getMetadata(LLVMContext::MD_prof)) {
55685568
if (MD->getOperand(0) != nullptr && isa<MDString>(MD->getOperand(0))) {
55695569
MDString *MDS = cast<MDString>(MD->getOperand(0));
@@ -5590,6 +5590,12 @@ Error BitcodeReader::materialize(GlobalValue *GV) {
55905590
I.setMetadata(LLVMContext::MD_prof, nullptr);
55915591
}
55925592
}
5593+
5594+
// Remove align from return attribute on CallInst.
5595+
if (auto *CI = dyn_cast<CallInst>(&I)) {
5596+
if (CI->getFunctionType()->getReturnType()->isVoidTy())
5597+
CI->removeAttribute(0, Attribute::Alignment);
5598+
}
55935599
}
55945600

55955601
// Look for functions that rely on old function attribute behavior.

llvm/lib/IR/AutoUpgrade.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4371,6 +4371,12 @@ void llvm::UpgradeFunctionAttributes(Function &F) {
43714371
Attribute NewAttr = Attribute::getWithByValType(F.getContext(), ByValTy);
43724372
F.addParamAttr(0, NewAttr);
43734373
}
4374+
4375+
// If function has void return type, check it has align attribute. It has no
4376+
// affect on the return type and no longer passes the verifier.
4377+
if (F.getReturnType()->isVoidTy() &&
4378+
F.hasAttribute(AttributeList::ReturnIndex, Attribute::Alignment))
4379+
F.removeAttribute(AttributeList::ReturnIndex, Attribute::Alignment);
43744380
}
43754381

43764382
static bool isOldLoopArgument(Metadata *MD) {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
; Check upgrade is removing the incompatible attributes on void return type.
2+
3+
; RUN: llvm-dis < %s.bc | FileCheck %s
4+
5+
; CHECK: define void @f()
6+
define align 8 void @f() {
7+
ret void
8+
}
9+
10+
define void @g() {
11+
; CHECK: call void @f()
12+
call align 8 void @f();
13+
ret void
14+
}
Binary file not shown.

0 commit comments

Comments
 (0)