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

    <tr>
        <th>Summary</th>
        <td>
            TypePromotion produces invalid IR (take 2)
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            backend:AArch64,
            crash
      </td>
    </tr>

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

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

<pre>
    ```ll
; RUN: opt -S -type-promotion < %s
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
target triple = "aarch64-unknown-linux-gnu"

define i1 @test(i8 %arg) {
  %arg.ext = zext i8 %arg to i64
  %trunc = trunc i64 %arg.ext to i3
 %switch.tableidx = xor i3 %trunc, 1
  %switch.maskindex = zext i3 %trunc to i8
  %switch.lobit = icmp ne i8 %switch.maskindex, 0
  ret i1 %switch.lobit
}
```
Results in a verifier error:
```
Both operands to a binary operator are not of the same type!
  %switch.tableidx = xor i64 %1, i32 1
in function test
```
The produced IR looks as follows:
```ll
define i1 @test(i8 %arg) {
  %arg.ext = zext i8 %arg to i64
  %1 = and i64 %arg.ext, 7
  %switch.tableidx = xor i64 %1, i32 1
  %2 = trunc i64 %1 to i32
  %switch.lobit = icmp ne i32 %2, 0
 ret i1 %switch.lobit
}
```
The symptoms here are similar to #58843, but the fix for that one did not fix this case.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VE2PqzYU_TVmc0UE10DIggXzokjdVNW81x9g4BLcGBvZZibpr69skpl5nVlUT6qUENs59-Mcjq9wTp41UcPKJ1YeE7H6ydhGy4vsk84Mt4ZV2fZRimVHlrWMP8Hzn78z3oJZPKTfIfW3hdLFmtl4aTQw_g0Ylm7De2HP5GEQXihxM6sHxo_AECmdGW8plTXjbfhyTGVeMd7GR9hVBeNtVaQyxwDIsU41x-3sezhD_KmIt3JR9CgghO2nqkhXfdHmVadK6vWanvX6FrY9BxqlJpA5sCLz5DzDWtaBgrBnhgdg-6cNCffDHV03Gn-HxRsWvIHQ8zvW21X3EbmtZFV8TBHw_A4Pir1K3087LzpFcrjGuKuxIPlbLobfIP9Q4B4yC3eReqDrh67eg2Kd-nOUMp3ceMh-XiBoUH-VNBTNHuGWfJTq5yx3PffH--Lhmm37TG5V3oHUIOCFrBwlWSBrjWW8_TLkyfgJzEJW6MEFAgI6qYW9bYfeWBCWQBsPZgQ_ETgxEwQrMvxCoc-ibq8iD-Qkx4eqUsO46j4aOXrhq-Z-TASLNcPa0wC_PYMy5uJAOBiNUubVfSb1uD3_o9fyiBJ6-JfLAsH9rwsSY_Czh_PNvfifbMUxZvlopF_xUdDd3ebFm9nBRJaiB5ycpRI29MOQl3Vd8FCoW330xSivMBoLfhIejCYY5BB9E_7wk3TQC0e7ZGj4cOAHkVCTV_scsz3Pi2RquqEahcD9ftyLA3EaD90oxqKri6zLup4nssEMMce8yqu8zItd2Ym8rOo8E_2INR5YkdEspNop9TLvjD0n0rmVmvJQlkWiREfKxQmM2In-QnpgvG3bOL3CrMJvDLG3wk1hVx4T24RMabeeHSsyJZ1377m99IqaH7eF_ngbyXezhhv4IpSMpmVYe3EhQIaHZLWqmbxfonXxxPB0ln5au11vZoankPz-Ewb9X9R7hqfIwjE8RSL_BAAA__8p99dk">