From 4eff9469475384a59a9da407e78aa00262edcdd0 Mon Sep 17 00:00:00 2001 From: Steven Wu Date: Tue, 11 May 2021 08:23:08 -0700 Subject: [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 --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp') diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 46db3ed..38d7b77 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(MD->getOperand(0))) { MDString *MDS = cast(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(&I)) { + if (CI->getFunctionType()->getReturnType()->isVoidTy()) + CI->removeAttribute(0, Attribute::Alignment); + } } // Look for functions that rely on old function attribute behavior. -- cgit v1.1