llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

llvm-stress causes DAGCombiner to produce an illegal BUILD_VECTOR

Open JonPsson opened this issue 9 years ago • 5 comments

Bugzilla Link 32422
Resolution FIXED
Resolved on Apr 05, 2017 07:11
Version trunk
OS Linux
Attachments reduced llvm-stress test case
CC @efriedma-quic,@RKSimon,@JonPsson

Extended Description

A nonsense function:

*** IR Dump After Module Verifier *** define void @​autogen_SD28844() #​0 { BB: %I = insertelement <8 x i8> zeroinitializer, i8 -95, i32 3 %I8 = insertelement <8 x i8> zeroinitializer, i8 -119, i32 2 %FC = uitofp <8 x i8> %I8 to <8 x float> %Cmp18 = fcmp uno <8 x float> zeroinitializer, %FC %I22 = insertelement <8 x i1> %Cmp18, i1 true, i32 5 br label %CF

CF: ; preds = %CF, %BB %Cmp40 = fcmp uno double 0xC663C682E9619F00, undef br i1 %Cmp40, label %CF, label %CF353

CF353: ; preds = %CF %E195 = extractelement <8 x i1> %I22, i32 4 ret void }

causes ISel to crash:

DAGCombiner transforms

26: DAG.dump() = SelectionDAG has 10 nodes: t0: ch = EntryToken t64: v8i16 = BUILD_VECTOR Constant:i32<0>, Constant:i32<0>, Constant:i32<0>, Constant:i32<0>, Constant:i32<0>, Constant:i32<0>, Constant:i32<0>, Constant:i32<0> t66: v8i16 = sign_extend_inreg t64, ValueType:ch:v8i1 t34: v8i16 = insert_vector_elt t66, Constant:i32<1>, Constant:i32<5> t19: ch = CopyToReg t0, Register:v8i16 %vreg0, t34

to

26: DAG.dump() = SelectionDAG has 8 nodes: t0: ch = EntryToken t76: v8i16 = BUILD_VECTOR Constant:i16<0>, Constant:i16<0>, Constant:i16<0>, Constant:i16<0>, Constant:i16<0>, Constant:i16<0>, Constant:i16<0>, Constant:i16<0> t34: v8i16 = insert_vector_elt t76, Constant:i32<1>, Constant:i32<5> t19: ch = CopyToReg t0, Register:v8i16 %vreg0, t34

, which later triggers (on BUILD_VECTOR)

/llvm/llvm-dev/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:921: void {anonymous}::SelectionDAGLegalize::LegalizeOp(llvm::SDNode*): Assertion `(TLI.getTypeAction(*DAG.getContext(), Op.getValueType()) == TargetLowering::TypeLegal || TLI.isTypeLegal(Op.getValueType()) || Op.getOpcode() == ISD::TargetConstant) && "Unexpected illegal type!"' failed.

This is because i16 is not a legal type on SystemZ, which means the BUILD_VECTOR was transformed incorrectly. Could it be that the BUILD_VECTOR should have TargetConstant operands, instead of Constant operands?

run with bin/llc -mtriple=s390x-linux-gnu -mcpu=z13

JonPsson avatar Mar 25 '17 17:03 JonPsson

rL299540

RKSimon avatar Apr 05 '17 14:04 RKSimon

https://reviews.llvm.org/D31651

JonPsson avatar Apr 04 '17 09:04 JonPsson

I think the problem here is just that the constant folding for SIGN_EXTEND_INREG in SelectionDAG::getNode() is producing constants with illegal types. Probably need to preserve the type of the operands to the BUILD_VECTOR.

efriedma-quic avatar Mar 31 '17 21:03 efriedma-quic

The arguments to the BUILD_VECTOR are i32 but BUILD_VECTOR (and SCALAR_TO_VECTOR) implicitly truncates integer arguments. The assertion looks like it's too strict here. Making it less strict fixes the crash but I didn't check the output itself.

Other backends have had this error in the past but the bugs I've looked at all appear to be working now. It's not clear to me if this is deliberate or just incidental.

llvmbot avatar Mar 31 '17 15:03 llvmbot

ping.

any idea anyone?

JonPsson avatar Mar 31 '17 06:03 JonPsson