When value of immediate in mips.nori.b is 255 (which has all ones in binary form
as 8bit integer) DAGCombiner and Legalizer would fall in an infinite loop.
DAGCombiner would try to simplify 'or %value, -1' by turning %value into UNDEF.
Legalizer will turn it back into Constant<0> which would then be again turned
into UNDEF by DAGCombiner. To avoid this loop we make UNDEF legal for MSA int
types on Mips.
Details
Diff Detail
Event Timeline
More detailed explanation follows:
Expansion for mips.nori.b goes something like this:
mips.nori.b %dst, %val, imm %dst = not (or %value, imm) %dst = xor (or %value, imm), -1
For -1 as immediate we should get:
%dst = xor (or %value, -1), -1 %dst = xor -1, -1 %dst = 0
When value of immediate is 255 (-1 for i8, so all bits are 1) issue shows up in DAGCombiner when it runs into node for XOR:
SelectionDAG:
... t31: v2i64 = BUILD_VECTOR Constant:i64<0>, Constant:i64<0> t2: i64,ch = CopyFromReg t0, Register:i64 %0 t28: v2i64 = insert_vector_elt t31, t2, Constant:i32<0> t4: i64,ch = CopyFromReg t0, Register:i64 %1 t30: v2i64 = insert_vector_elt t28, t4, Constant:i32<1> t6: v16i8 = bitcast t30 t24: v16i8 = or t6, t23 t25: v16i8 = xor t24, t23 ... t23: v16i8 = BUILD_VECTOR Constant:i32<255>, Constant:i32<255>, ...
-DAGCombiner::visitXOR() is called which in turns calles SimplifyDemandedBits().
--SimplifyDemandedBits() for XOR will call SimplifyDemandedBits() for OR.
--SimplifyDemandedBits() for OR will call SimplifyDemandedBits() for Operand(0)
--SimplifyDemandedBits() for Operand(0) will make a new UNDEF node.
-Legalizer for Mips will replace UNDEF node with a new Constant<0> node.
-DAGCombiner::visitXOR() is called which again makes a new UNDEF node (this time from Constant<0>).
Legalizer for Mips will replace UNDEF node with a new Constant<0> node.
...
now we are in a loop.
Making UNDEF legal avoids making a loop. It also produces shorter code which is why there are changes to other tests.