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

    <tr>
        <th>Summary</th>
        <td>
            [MLIR] Misleading parse error for values not defined inside regions
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    ```
func @foo_parallel() {
  %c0 = arith.constant 0 : index
  %c1 = arith.constant 1 : index
  %c4 = arith.constant 4 : index
  %c8 = arith.constant 8 : index
  %c32 = arith.constant 32 : index
  %c64 = arith.constant 64 : index
  scf.parallel (%arg3, %arg4, %arg5) = (%c0, %c0, %c0) to (%c32, %c64, %c64) step (%c4, %c4, %c8) {
  }
  return
}

func @bar() {
  %64 = arith.constant 64 : index
}
```
```
test.mlir:8:3: error: 'scf.parallel' op using value defined outside the region
  scf.parallel (%arg3, %arg4, %arg5) = (%c0, %c0, %c0) to (%c32, %64, %c64) step (%c4, %c4, %c8) {
  ^
test.mlir:8:3: note: see current operation: "scf.parallel"(%0, %0, %0, %4, <<UNKNOWN SSA VALUE>>, %5, %2, %2, %3) ({
^bb0(%arg0: index, %arg1: index, %arg2: index):
  "scf.yield"() : () -> ()
}) {operand_segment_sizes = dense<[3, 3, 3, 0]> : vector<4xi32>} : (index, index, index, index, index, index, index, index, index) -> ()
test.mlir:1:1: note: required by region isolation constraints
func @foo_parallel() {
^
```

I *think* "undecared SSA value name" is the right error message here as opposed to "defined outside the region". `%64` has not been defined above and the current message can be misleading.

Separately, the location info doesn't say which value it's referring to out of the nine values therein.

CC: @joker-eph @River707 @lattner 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy9VE2P2zgM_TXOhZjAke04PuSQJl2g2HYW6KDtcSDbtK3WkbKSnDb99aXkjySzRlFgiwKyRUkU-fhIKlfl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