Skip to content

Commit 5fa3949

Browse files
tblahchencha3
authored andcommitted
[mlir][LLVM] erase call mappings in forgetMapping() (llvm#84955)
It looks like the mappings for call instructions were forgotten here. This fixes a bug in OpenMP when in-lining a region containing call operations multiple times. OpenMP array reductions 4/6 Previous PR: llvm#84954 Next PR: llvm#84957
1 parent f0e7bb5 commit 5fa3949

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

mlir/lib/Target/LLVMIR/ModuleTranslation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,8 @@ void ModuleTranslation::forgetMapping(Region &region) {
716716
branchMapping.erase(&op);
717717
if (isa<LLVM::GlobalOp>(op))
718718
globalsMapping.erase(&op);
719+
if (isa<LLVM::CallOp>(op))
720+
callMapping.erase(&op);
719721
llvm::append_range(
720722
toProcess,
721723
llvm::map_range(op.getRegions(), [](Region &r) { return &r; }));
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// RUN: mlir-translate -mlir-to-llvmir %s | FileCheck %s
2+
3+
// Test that we don't crash when there is a call operation in the combiner
4+
5+
omp.reduction.declare @add_f32 : f32
6+
init {
7+
^bb0(%arg: f32):
8+
%0 = llvm.mlir.constant(0.0 : f32) : f32
9+
omp.yield (%0 : f32)
10+
}
11+
combiner {
12+
^bb1(%arg0: f32, %arg1: f32):
13+
// test this call here:
14+
llvm.call @test_call() : () -> ()
15+
%1 = llvm.fadd %arg0, %arg1 : f32
16+
omp.yield (%1 : f32)
17+
}
18+
19+
llvm.func @simple_reduction(%lb : i64, %ub : i64, %step : i64) {
20+
%c1 = llvm.mlir.constant(1 : i32) : i32
21+
%0 = llvm.alloca %c1 x i32 : (i32) -> !llvm.ptr
22+
omp.parallel reduction(@add_f32 %0 -> %prv : !llvm.ptr) {
23+
%1 = llvm.mlir.constant(2.0 : f32) : f32
24+
%2 = llvm.load %prv : !llvm.ptr -> f32
25+
%3 = llvm.fadd %1, %2 : f32
26+
llvm.store %3, %prv : f32, !llvm.ptr
27+
omp.terminator
28+
}
29+
llvm.return
30+
}
31+
32+
llvm.func @test_call() -> ()
33+
34+
// Call to the troublesome function will have been inlined twice: once into
35+
// main and once into the outlined function
36+
// CHECK: call void @test_call()
37+
// CHECK: call void @test_call()

0 commit comments

Comments
 (0)