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

    <tr>
        <th>Summary</th>
        <td>
            i128: "Unexpected truncation" failure in SystemZDAGToDAGISel::getAddressOperands()
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            backend:SystemZ
      </td>
    </tr>

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

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

<pre>
    Another test case with problem truncating from i128:

```
@safe_rshift_func_uint8_t_u_u_left = dso_local local_unnamed_addr global i8 0, align 2
@func_54_p_58 = dso_local local_unnamed_addr global i32 0, align 4
@g_38_0_0 = internal global i32 0, align 4
@g_76 = internal unnamed_addr global i128 6, align 8

define dso_local void @main() {
entry:
 %g_76.promoted13.i.i.i = load i128, ptr @g_76, align 8
  %0 = add i128 %g_76.promoted13.i.i.i, 5
  store i128 %0, ptr @g_76, align 8
  store i32 6, ptr @func_54_p_58, align 4
  %cmp6.i.i = icmp ugt i128 %0, 7
 %1 = load i8, ptr @safe_rshift_func_uint8_t_u_u_left, align 2
  %conv8.i.i = zext i8 %1 to i32
  %sh_prom.i.i = trunc i128 %0 to i32
  %shr.i.i = lshr i32 %conv8.i.i, %sh_prom.i.i
  %conv10.i.i = select i1 %cmp6.i.i, i32 0, i32 %shr.i.i
  store i32 %conv10.i.i, ptr @g_38_0_0, align 4
  ret void
}
```

llc -mtriple=s390x-linux-gnu -mcpu=z13 tcAM.ll
SystemZDAGToDAGISel::getAddressOperands(const {anonymous}::SystemZAddressingMode&, llvm::EVT, llvm::SDValue&, llvm::SDValue&) const: Assertion `VT == MVT::i32 && Base.getValueType() == MVT::i64 && "Unexpected truncation"' failed.

SelectCode(Node):
```
(gdb) p CurDAG->dump()
SelectionDAG has 30 nodes:
  t0: ch,glue = EntryToken
  t45: i64 = SystemZISD::PCREL_WRAPPER TargetGlobalAddress:i64<ptr @g_76> 0
    t41: i64 = SystemZISD::PCREL_WRAPPER TargetGlobalAddress:i64<ptr @safe_rshift_func_uint8_t_u_u_left> 0
  t28: i32,ch = load<(dereferenceable load (s8) from @safe_rshift_func_uint8_t_u_u_left, align 2), zext from i8> t0, t41, undef:i64
  t4: i128,ch = load<(dereferenceable load (s128) from @g_76, align 8)> t0, t45, undef:i64
  t6: i128 = add t4, Constant:i128<5>
  t46: i32 = TargetConstant<0>
            t17: i32 = truncate t6
          t18: i32 = srl t28, t17
            t34: i32 = SystemZISD::UCMP128HI t6, Constant:i128<7>
          t49: ch,glue = CopyToReg t0, Register:i32 $cc, t34
        t37: i32 = LOCHIMux t18, TargetConstant:i64<0>, TargetConstant:i32<15>, TargetConstant:i32<4>, t49:1
      t24: ch = STRL<Mem:(store (s32) into @g_38_0_0)> t37, TargetGlobalAddress:i64<ptr @g_38_0_0> 0, t0
      t7: ch = store<(store (s128) into @g_76, align 8)> t4:1, t6, t45, undef:i64
        t43: i64 = SystemZISD::PCREL_WRAPPER TargetGlobalAddress:i64<ptr @func_54_p_58> 0
      t31: ch = store<(store (s32) into @func_54_p_58)> t0, Constant:i32<6>, t43, undef:i64
    t33: ch = TokenFactor t24, t28:1, t7, t31
  t23: ch = Return t33


$233 = void
(gdb) p Node->dump()
t18: i32 = srl t28, t17
```


</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysV1lv2zgQ_jX0CxFDInX5wQ-unKRZNNsgcbPAvgi0NJa1pUiBpNqkv35BStERu00K9IBd23N8c30zYlpXpQBYo_ADIqT9DlXJRIEIQeF2wVpzlGr9lxR3WkvhL_ayeF5vhDRHUNiANjhnGvD3yhxxo-SeQ42NakXOTCVKfFCyxpVPEkQ3yNsi7-U18vp_3cfA0-wAmdLH6mCyQyvyrK2ESTKTtVmbcTgYjOgWF1pmXOaMY_eatUKwGoqMFYXCJZd7xnGVYA-RFDNelQKTwYOzGgZZk4XJ-41RMrUWDNbKjC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