Derived from #92480. This PR introduces reduction semantics into loops for DO CONCURRENT REDUCE. The `fir.do_loop` operation now invisibly has the `operandSegmentsizes` attribute and takes variable-length reduction operands with their operations given as `fir.reduce_attr`. For the sake of compatibility, `fir.do_loop`'s builder has additional arguments at the end. The `iter_args` operand should be placed in front of the declaration of result types, so the new operand for reduction variables (`reduce`) is put in the middle of arguments.
18 lines
695 B
Plaintext
18 lines
695 B
Plaintext
// Test the reduction semantics of fir.do_loop
|
|
// RUN: fir-opt %s | FileCheck %s
|
|
|
|
func.func @reduction() {
|
|
%bound = arith.constant 10 : index
|
|
%step = arith.constant 1 : index
|
|
%sum = fir.alloca i32
|
|
// CHECK: %[[VAL_0:.*]] = fir.alloca i32
|
|
// CHECK: fir.do_loop %[[VAL_1:.*]] = %[[VAL_2:.*]] to %[[VAL_3:.*]] step %[[VAL_4:.*]] unordered reduce(#fir.reduce_attr<add> -> %[[VAL_0]] : !fir.ref<i32>) {
|
|
fir.do_loop %iv = %step to %bound step %step unordered reduce(#fir.reduce_attr<add> -> %sum : !fir.ref<i32>) {
|
|
%index = fir.convert %iv : (index) -> i32
|
|
%1 = fir.load %sum : !fir.ref<i32>
|
|
%2 = arith.addi %index, %1 : i32
|
|
fir.store %2 to %sum : !fir.ref<i32>
|
|
}
|
|
return
|
|
}
|