DAGTypeLegalizer::PromoteIntRes_TRUNCATE() did previously not handle the case where the operand needs to be widened, which resultet in a llvm_unreachable()l.
This was discovered with llvm-stress and reported at https://bugs.llvm.org/show_bug.cgi?id=32275. The stress test case is included also in this patch as a regression test for SystemZ.
The test case involves a truncate from v4i8 to v4i1. On SystemZ, v4i8 should be widened to v16i8.
t17: v16i8,ch = CopyFromReg t0, Register:v16i8 %vreg13
t18: v4i8 = extract_subvector t17, Constant:i32<0>
t19: v4i1 = truncate t18The patch net result is (after type legalization)
t264: i32 = extract_vector_elt t17, Constant:i32<0>
t260: i32 = extract_vector_elt t17, Constant:i32<1>
t256: i32 = extract_vector_elt t17, Constant:i32<2>
t252: i32 = extract_vector_elt t17, Constant:i32<3>
t222: v4i32 = BUILD_VECTOR t264, t260, t256, t252
t112: v4i32 = BUILD_VECTOR Constant:i32<1>, Constant:i32<1>, Constant:i32<1>, Constant:i32<1>
t224: v4i32 = and t222, t112
t270: v4i32 = sign_extend_inreg t224, ValueType:ch:v4i1The final output does not look optimal, but since this is so rare, it should not matter.
Reduced with bugpoint:
define void @autogen_SD29574() { BB: %B15 = sub <4 x i8> undef, zeroinitializer br label %CF34 CF34: ; preds = %CF34, %BB %Tr24 = trunc <4 x i8> %B15 to <4 x i1> %Cmp26 = icmp slt <4 x i1> %Tr24, undef %E28 = extractelement <4 x i1> %Cmp26, i32 3 br i1 %E28, label %CF34, label %CF36 CF36: ; preds = %CF34 ret void }