Skip to content

Commit 9d95165

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 3494056 commit 9d95165

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
@@ -5475,8 +5475,8 @@ Error BitcodeReader::materialize(GlobalValue *GV) {
54755475
}
54765476
}
54775477

5478-
// "Upgrade" older incorrect branch weights by dropping them.
54795478
for (auto &I : instructions(F)) {
5479+
// "Upgrade" older incorrect branch weights by dropping them.
54805480
if (auto *MD = I.getMetadata(LLVMContext::MD_prof)) {
54815481
if (MD->getOperand(0) != nullptr && isa<MDString>(MD->getOperand(0))) {
54825482
MDString *MDS = cast<MDString>(MD->getOperand(0));
@@ -5503,6 +5503,12 @@ Error BitcodeReader::materialize(GlobalValue *GV) {
55035503
I.setMetadata(LLVMContext::MD_prof, nullptr);
55045504
}
55055505
}
5506+
5507+
// Remove align from return attribute on CallInst.
5508+
if (auto *CI = dyn_cast<CallInst>(&I)) {
5509+
if (CI->getFunctionType()->getReturnType()->isVoidTy())
5510+
CI->removeAttribute(0, Attribute::Alignment);
5511+
}
55065512
}
55075513

55085514
// 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
@@ -4319,6 +4319,12 @@ void llvm::UpgradeFunctionAttributes(Function &F) {
43194319
Attribute NewAttr = Attribute::getWithByValType(F.getContext(), ByValTy);
43204320
F.addParamAttr(0, NewAttr);
43214321
}
4322+
4323+
// If function has void return type, check it has align attribute. It has no
4324+
// affect on the return type and no longer passes the verifier.
4325+
if (F.getReturnType()->isVoidTy() &&
4326+
F.hasAttribute(AttributeList::ReturnIndex, Attribute::Alignment))
4327+
F.removeAttribute(AttributeList::ReturnIndex, Attribute::Alignment);
43224328
}
43234329

43244330
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)