Open
Description
git version: e43d64e
system: Ubuntu 18.04.6 LTS
Description:
I am experiencing an inconsistent result when executing the same MLIR program with and without --sccp
.
Steps to Reproduce:
1. MLIR Program (a.mlir):
a.mlir:
module {
func.func @main() {
%true = arith.constant true
%c10283417 = arith.constant 10283417 : index
%low, %high = arith.mului_extended %c10283417, %c10283417 : index
%2 = arith.subi %true, %true : i1
%3:3 = scf.if %2 -> (index, index, index) {
%c-5111992125488369343 = arith.constant -5111992125488369343 : index
scf.yield %c-5111992125488369343, %c-5111992125488369343, %c-5111992125488369343 : index, index, index
} else {
%c20 = arith.constant 20 : index
%c5 = arith.constant 5 : index
%17 = arith.shrsi %high, %c5 : index
scf.yield %c20, %17, %c5 : index, index, index
}
%low_5, %high_6 = arith.mului_extended %c10283417, %3#2 : index
vector.print str "%83="
vector.print %3#1 : index
vector.print str "%103="
vector.print %low_5 : index
return
}
}
2. Command to Run without --sccp
:
/data/szy/workspace/llvm-release/llvm-project/build/bin/mlir-opt a.mlir -convert-arith-to-llvm \
-convert-scf-to-cf -convert-vector-to-llvm -convert-arith-to-llvm -convert-cf-to-llvm -convert-func-to-llvm \
-reconcile-unrealized-casts | timeout 10 /data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-cpu-runner -e main \
-entry-point-result=void --shared-libs=/data/szy/MLIR/llvm-release/llvm-project/build/lib/libmlir_c_runner_utils.so \
--shared-libs=/data/szy/MLIR/llvm-release/llvm-project/build/lib/libmlir_runner_utils.so \
--shared-libs=/data/szy/MLIR/llvm-release/llvm-project/build/lib/libmlir_async_runtime.so
3. Output without --sccp
::
%83=0
%103=51417085
4. Command to Run with --sccp
:
/data/szy/workspace/llvm-release/llvm-project/build/bin/mlir-opta.mlir -convert-arith-to-llvm \
-convert-scf-to-cf -convert-vector-to-llvm -convert-arith-to-llvm -convert-cf-to-llvm --sccp -convert-func-to-llvm \
-reconcile-unrealized-casts | timeout 10 /data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-cpu-runner -e main \
-entry-point-result=void --shared-libs=/data/szy/MLIR/llvm-release/llvm-project/build/lib/libmlir_c_runner_utils.so \
--shared-libs=/data/szy/MLIR/llvm-release/llvm-project/build/lib/libmlir_runner_utils.so \
--shared-libs=/data/szy/MLIR/llvm-release/llvm-project/build/lib/libmlir_async_runtime.so
5. Output with --sccp
:
%83=0
%103=9770893153790023897
6. Analysis for this case :
After running with --sccp
, a.mlir is transformed as follows:
It returns the result of multiplying %2 (13334751948221182273)
and %4 (10283417)
,
whereas it should return the result of multiplying 5
and 10283417
.
module {
llvm.mlir.global private constant @vector_print_str_0(dense<[37, 49, 48, 51, 61, 0]> : tensor<6xi8>) {addr_space = 0 : i32} : !llvm.array<6 x i8>
llvm.func @printNewline()
llvm.func @printU64(i64)
llvm.func @printString(!llvm.ptr)
llvm.mlir.global private constant @vector_print_str(dense<[37, 56, 51, 61, 0]> : tensor<5xi8>) {addr_space = 0 : i32} : !llvm.array<5 x i8>
func.func @main() {
%0 = llvm.mlir.addressof @vector_print_str_0 : !llvm.ptr
%1 = llvm.mlir.addressof @vector_print_str : !llvm.ptr
%2 = llvm.mlir.constant(13334751948221182273 : i128) : i128
%3 = llvm.mlir.constant(false) : i1
%4 = llvm.mlir.constant(10283417 : i128) : i128
%5 = llvm.mlir.constant(5 : index) : i64
%6 = llvm.mlir.constant(-5111992125488369343 : index) : i64
%7 = llvm.mlir.constant(0 : index) : i64
llvm.cond_br %3, ^bb1, ^bb2
^bb1: // pred: ^bb0
llvm.br ^bb3(%6, %6 : i64, i64)
^bb2: // pred: ^bb0
%8 = llvm.ashr %7, %5 : i64
llvm.br ^bb3(%8, %5 : i64, i64)
^bb3(%9: i64, %10: i64): // 2 preds: ^bb1, ^bb2
%11 = builtin.unrealized_conversion_cast %10 : i64 to index
%12 = builtin.unrealized_conversion_cast %9 : i64 to index
%13 = builtin.unrealized_conversion_cast %12 : index to i64
llvm.br ^bb4
^bb4: // pred: ^bb3
%14 = builtin.unrealized_conversion_cast %11 : index to i64
%15 = llvm.mul %2, %4 : i128
%16 = llvm.trunc %15 : i128 to i64
llvm.call @printString(%1) : (!llvm.ptr) -> ()
llvm.call @printU64(%13) : (i64) -> ()
llvm.call @printNewline() : () -> ()
llvm.call @printString(%0) : (!llvm.ptr) -> ()
llvm.call @printU64(%16) : (i64) -> ()
llvm.call @printNewline() : () -> ()
return
}
}