<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/137509>137509</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [mlir] Inconsistent output when executing MLIR program with `--sccp`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            mlir
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          Emilyaxe
      </td>
    </tr>
</table>

<pre>
    git version: e43d64ebe92ed0f61d6ba70

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
  }
}
``` 





</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsWVuP6ygS_jXkBTnCYHx5yENOpyMdafaiOTvPEbZJwi4BC3B3Z379CnASJ3H6sqOz-7AjRbRtqr66QBVVNLNW7BTnC0C_Abqasd7ttVk8H4Q8sjc-q3V7XOyEgy_cWKEVIEvIM9LmGa95hXmLtnna5jUrEEBLgJb2aB0_eDKQo9_qXrkepuUcZfMc_vKPHyAf6AAmABO44rYxonMRGqDld8gOkL913AiuGqF2kCkoVKOVFdZx5aDhtpcOvu65gvyNN73zVG7PoWUHDv_yy_dfYWf0zrADfBVuD5lqw4PunVcqSWzTdCBHc3ilyg_HOwudhr_yzui2b3jU6EzhidI5BHgJ8DKI-fsgBuCSzQ9SGICrOB1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