Skip to content

[MLIR][LLVMIR] Import: fix llvm.call attribute inheritance #130221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions mlir/lib/Target/LLVMIR/ModuleImport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2263,10 +2263,15 @@ LogicalResult ModuleImport::convertInvokeAttributes(llvm::InvokeInst *inst,
LogicalResult ModuleImport::convertCallAttributes(llvm::CallInst *inst,
CallOp op) {
setFastmathFlagsAttr(inst, op.getOperation());
// Query the attributes directly instead of using `inst->getFnAttr(Kind)`, the
// latter does additional lookup to the parent and inherits, changing the
// semantics too early.
llvm::AttributeList callAttrs = inst->getAttributes();

op.setTailCallKind(convertTailCallKindFromLLVM(inst->getTailCallKind()));
op.setConvergent(inst->isConvergent());
op.setNoUnwind(inst->doesNotThrow());
op.setWillReturn(inst->hasFnAttr(llvm::Attribute::WillReturn));
op.setConvergent(callAttrs.getFnAttr(llvm::Attribute::Convergent).isValid());
op.setNoUnwind(callAttrs.getFnAttr(llvm::Attribute::NoUnwind).isValid());
op.setWillReturn(callAttrs.getFnAttr(llvm::Attribute::WillReturn).isValid());

llvm::MemoryEffects memEffects = inst->getMemoryEffects();
ModRefInfo othermem = convertModRefInfoFromLLVM(
Expand Down
21 changes: 20 additions & 1 deletion mlir/test/Target/LLVMIR/Import/call-argument-attributes.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; RUN: mlir-translate -import-llvm %s | FileCheck %s
; RUN: mlir-translate -import-llvm -split-input-file %s | FileCheck %s

; CHECK-LABEL: llvm.func @somefunc(i32, !llvm.ptr)
declare void @somefunc(i32, ptr)
Expand All @@ -20,3 +20,22 @@ define i16 @test_call_arg_attrs_indirect(i16 %0, ptr %1) {
%3 = tail call signext i16 %1(i16 noundef signext %0)
ret i16 %3
}

; // -----

%struct.S = type { i8 }

; CHECK-LABEL: @t
define void @t(i1 %0) #0 {
%3 = alloca %struct.S, align 1
; CHECK-NOT: llvm.call @z(%1) {no_unwind} : (!llvm.ptr) -> ()
; CHECK: llvm.call @z(%1) : (!llvm.ptr) -> ()
call void @z(ptr %3)
ret void
}

define linkonce_odr void @z(ptr %0) #0 {
ret void
}

attributes #0 = { nounwind }