Skip to content

Commit 17c7096

Browse files
committed
Bring back useful tests for invalid IR
1 parent 63c1a3e commit 17c7096

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

mlir/test/Dialect/OpenMP/invalid.mlir

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,87 @@ cleanup {
639639

640640
// -----
641641

642+
func.func @foo(%lb : index, %ub : index, %step : index) {
643+
%c1 = arith.constant 1 : i32
644+
%0 = llvm.alloca %c1 x i32 : (i32) -> !llvm.ptr
645+
%1 = llvm.alloca %c1 x i32 : (i32) -> !llvm.ptr
646+
647+
// expected-error @below {{expected symbol reference @foo to point to a reduction declaration}}
648+
omp.wsloop reduction(@foo %0 -> %prv : !llvm.ptr) {
649+
omp.loop_nest (%iv) : index = (%lb) to (%ub) step (%step) {
650+
%2 = arith.constant 2.0 : f32
651+
omp.yield
652+
}
653+
omp.terminator
654+
}
655+
return
656+
}
657+
658+
// -----
659+
660+
omp.declare_reduction @add_f32 : f32
661+
init {
662+
^bb0(%arg: f32):
663+
%0 = arith.constant 0.0 : f32
664+
omp.yield (%0 : f32)
665+
}
666+
combiner {
667+
^bb1(%arg0: f32, %arg1: f32):
668+
%1 = arith.addf %arg0, %arg1 : f32
669+
omp.yield (%1 : f32)
670+
}
671+
672+
func.func @foo(%lb : index, %ub : index, %step : index) {
673+
%c1 = arith.constant 1 : i32
674+
%0 = llvm.alloca %c1 x i32 : (i32) -> !llvm.ptr
675+
676+
// expected-error @below {{accumulator variable used more than once}}
677+
omp.wsloop reduction(@add_f32 %0 -> %prv : !llvm.ptr, @add_f32 %0 -> %prv1 : !llvm.ptr) {
678+
omp.loop_nest (%iv) : index = (%lb) to (%ub) step (%step) {
679+
%2 = arith.constant 2.0 : f32
680+
omp.yield
681+
}
682+
omp.terminator
683+
}
684+
return
685+
}
686+
687+
// -----
688+
689+
omp.declare_reduction @add_f32 : f32
690+
init {
691+
^bb0(%arg: f32):
692+
%0 = arith.constant 0.0 : f32
693+
omp.yield (%0 : f32)
694+
}
695+
combiner {
696+
^bb1(%arg0: f32, %arg1: f32):
697+
%1 = arith.addf %arg0, %arg1 : f32
698+
omp.yield (%1 : f32)
699+
}
700+
atomic {
701+
^bb2(%arg2: !llvm.ptr, %arg3: !llvm.ptr):
702+
%2 = llvm.load %arg3 : !llvm.ptr -> f32
703+
llvm.atomicrmw fadd %arg2, %2 monotonic : !llvm.ptr, f32
704+
omp.yield
705+
}
706+
707+
func.func @foo(%lb : index, %ub : index, %step : index, %mem : memref<1xf32>) {
708+
%c1 = arith.constant 1 : i32
709+
710+
// expected-error @below {{expected accumulator ('memref<1xf32>') to be the same type as reduction declaration ('!llvm.ptr')}}
711+
omp.wsloop reduction(@add_f32 %mem -> %prv : memref<1xf32>) {
712+
omp.loop_nest (%iv) : index = (%lb) to (%ub) step (%step) {
713+
%2 = arith.constant 2.0 : f32
714+
omp.yield
715+
}
716+
omp.terminator
717+
}
718+
return
719+
}
720+
721+
// -----
722+
642723
func.func @omp_critical2() -> () {
643724
// expected-error @below {{expected symbol reference @excl to point to a critical declaration}}
644725
omp.critical(@excl) {

0 commit comments

Comments
 (0)