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

    <tr>
        <th>Summary</th>
        <td>
            [AIX][toc-data] Miscompile when accessing tocdata variable at non-zero offset
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            miscompilation,
            platform:aix
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          hubert-reinterpretcast
      </td>
    </tr>
</table>

<pre>
    Consider:
```
unsigned int x = 0x0D002A00;
int main(void) { return 0xff & (x >> 8); }
```

The following IR, generated using the above C program, generates incorrect assembly for AIX out of `llc`:
```
@x = local_unnamed_addr global i32 218114560, align 4 #0

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none)
define i32 @main() local_unnamed_addr #1 {
entry:
  %0 = load i32, ptr @x, align 4
  %shr = lshr i32 %0, 8
  %and = and i32 %shr, 255
  ret i32 %and
}

attributes #0 = { "toc-data" }
```

In particular, the value loaded is byte value for the most significant byte (not the second least significant byte):
```
$ llc \
<<<$'@x = local_unnamed_addr global i32 218114560, align 4 #0\n\n; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none)\ndefine i32 @main() local_unnamed_addr #1 {\nentry:\n  %0 = load i32, ptr @x, align 4\n  %shr = lshr i32 %0, 8\n  %and = and i32 %shr, 255\n  ret i32 %and\n}\n\nattributes #0 = { "toc-data" }' \
-mtriple=powerpc-ibm-aix - -o - | grep -C2 lbz
.main:
# %bb.0: # %entry
        lbz 3, x[TD](2)
 blr
L..main0:
```

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVU2P2zYQ_TXjy0AGNZJs-eCDLcfAAu2lyCG3gJJGMguKFEhq186vLyjLzqZIUqS91JD1QT7Ox5tHjvRe9YZ5D8URiAZpWs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