$ mlir-translate --mlir-to-llvmir out/sum_relu.llvm.mlir -o out/sum_relu.ll && sed -n '/^define/,/^}/p' out/sum_relu.ll
what it printed on the machine that wrote this lab
define float @sum_relu(ptr %0, ptr %1, i64 %2, i64 %3, i64 %4) {
%6 = insertvalue { ptr, ptr, i64, [1 x i64], [1 x i64] } poison, ptr %0, 0
%7 = insertvalue { ptr, ptr, i64, [1 x i64], [1 x i64] } %6, ptr %1, 1
%8 = insertvalue { ptr, ptr, i64, [1 x i64], [1 x i64] } %7, i64 %2, 2
%9 = insertvalue { ptr, ptr, i64, [1 x i64], [1 x i64] } %8, i64 %3, 3, 0
%10 = insertvalue { ptr, ptr, i64, [1 x i64], [1 x i64] } %9, i64 %4, 4, 0
%11 = extractvalue { ptr, ptr, i64, [1 x i64], [1 x i64] } %10, 3
%12 = alloca [1 x i64], i64 1, align 8
store [1 x i64] %11, ptr %12, align 4
%13 = getelementptr [1 x i64], ptr %12, i32 0, i64 0
%14 = load i64, ptr %13, align 4
br label %15
15: ; preds = %19, %5
%16 = phi i64 [ %25, %19 ], [ 0, %5 ]
%17 = phi float [ %24, %19 ], [ 0.000000e+00, %5 ]
%18 = icmp slt i64 %16, %14
br i1 %18, label %19, label %26
19: ; preds = %15
%20 = extractvalue { ptr, ptr, i64, [1 x i64], [1 x i64] } %10, 1
%21 = getelementptr inbounds nuw float, ptr %20, i64 %16
%22 = load float, ptr %21, align 4
%23 = call float @llvm.maximum.f32(float %22, float 0.000000e+00)
%24 = fadd float %17, %23
%25 = add i64 %16, 1
br label %15
26: ; preds = %15
ret float %17
}
The descriptor struct is rebuilt with insertvalue (and even spilled to an
alloca) just to read one field. This looks terrible and costs nothing:
opt's SROA/instcombine erase it. Do NOT judge MLIR output before -O2.
Note the two `phi` nodes: they are the block arguments of STEP 1.