Skip to content

Commit 17717c4

Browse files
committed
[MLIR][LLVMIR] Import: fix function attribute inheritance on call attributes
Before this PR `inst->getFnAttr(Kind)` fallbacks to check if the parent has an attribute, which breaks roundtriping the LLVM IR. It's possible to argue that this small optimization isn't harmful, but seems too early if it's breaking roundtrip behavior.
1 parent f3effc2 commit 17717c4

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

mlir/lib/Target/LLVMIR/ModuleImport.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2263,10 +2263,15 @@ LogicalResult ModuleImport::convertInvokeAttributes(llvm::InvokeInst *inst,
22632263
LogicalResult ModuleImport::convertCallAttributes(llvm::CallInst *inst,
22642264
CallOp op) {
22652265
setFastmathFlagsAttr(inst, op.getOperation());
2266+
// Query the attributes directly instead of using `inst->getFnAttr(Kind)`, the
2267+
// latter does additional lookup to the parent and inherits, changing the
2268+
// semantics too early.
2269+
llvm::AttributeList callAttrs = inst->getAttributes();
2270+
22662271
op.setTailCallKind(convertTailCallKindFromLLVM(inst->getTailCallKind()));
2267-
op.setConvergent(inst->isConvergent());
2268-
op.setNoUnwind(inst->doesNotThrow());
2269-
op.setWillReturn(inst->hasFnAttr(llvm::Attribute::WillReturn));
2272+
op.setConvergent(callAttrs.getFnAttr(llvm::Attribute::Convergent).isValid());
2273+
op.setNoUnwind(callAttrs.getFnAttr(llvm::Attribute::NoUnwind).isValid());
2274+
op.setWillReturn(callAttrs.getFnAttr(llvm::Attribute::WillReturn).isValid());
22702275

22712276
llvm::MemoryEffects memEffects = inst->getMemoryEffects();
22722277
ModRefInfo othermem = convertModRefInfoFromLLVM(
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; RUN: mlir-translate -import-llvm -split-input-file %s | FileCheck %s
2+
3+
%struct.S = type { i8 }
4+
5+
; CHECK-LABEL: @t
6+
define void @t(i1 %0) #0 {
7+
%3 = alloca %struct.S, align 1
8+
; CHECK-NOT: llvm.call @z(%1) {no_unwind} : (!llvm.ptr) -> ()
9+
; CHECK: llvm.call @z(%1) : (!llvm.ptr) -> ()
10+
call void @z(ptr %3)
11+
ret void
12+
}
13+
14+
define linkonce_odr void @z(ptr %0) #0 {
15+
ret void
16+
}
17+
18+
attributes #0 = { nounwind }

0 commit comments

Comments
 (0)