<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none"><!-- p { margin-top: 0px; margin-bottom: 0px; }--></style>
</head>
<body dir="ltr" style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
<p>Hello,<br>
</p>
<p>This example input crashes if you run it through llc on x86.<br>
</p>
<p>[begin example]<br>
</p>
<div>
<div>; ModuleID = 'test'</div>
<div><br>
</div>
<div>%struct_2 = type { [90000 x %struct_1] }</div>
<div>%struct_1 = type { i8 }</div>
<div><br>
</div>
<div>define void @testFcn(%struct_2 %in1) {</div>
<div>testFcn_entry:</div>
<div>  %in1_ = alloca %struct_2</div>
<div>  store %struct_2 %in1, %struct_2* %in1_, align 8</div>
<div>  %localStruct_ = alloca %struct_2</div>
<div>  store %struct_2 %in1, %struct_2* %localStruct_, align 8</div>
<div>  br label %exit</div>
<div><br>
</div>
<div>exit:                                             ; preds = %testFcn_entry</div>
<div>  ret void</div>
<div>}<br>
</div>
<div><span style="font-size: 12pt;">[end example]</span></div>
</div>
<div><br>
</div>
<div>It looks like at some stage of the backend compiler flow there is a "merge_values" instruction generated where the number of inputs exceeds 16k, but the number of inputs is stored in an unsigned short.  When this instruction is being translated into x86
 machine code, then there is an out of bounds access:<br>
</div>
<div>
<div>~> llc bug-simple.bc </div>
<div>llc: /local/martind/oss/llvm-3.5.0.src/include/llvm/CodeGen/SelectionDAGNodes.h:649: llvm::EVT llvm::SDNode::getValueType(unsigned int) const: Assertion `ResNo < NumValues && "Illegal result number!"' failed.</div>
<div><br>
</div>
<div>Probably the truncation of NumOperands should be caught directly with an assertion in the SDNode constructor.<br>
</div>
<div><br>
One other interesting aspect of it is that if you make the struct_2 type a smaller matrix, like:<br>
</div>
<div><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">%struct_2 = type { [65534 x %struct_1] }</span><br>
</div>
<div><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);"><br>
</span></div>
<div><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">Then you don't get a crash, instead it takes about 20+ minutes to process and you get a lot of movb instructions out - like 200k or
 so. Callgrind says that 33% of the time consumed is directly in llvm::SUnit::ComputeHeight(). Clearly something has gone badly non-linear for this case.</span></div>
</div>
<div><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);"><br>
</span></div>
<div><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">I looked at what clang is doing for a similar construct and I see it generates a memcpy intrinsic instead of the direct load/store.
 I'm now doing that in my own front-end, but it seems like this is intended to be supported so I thought I'd report it.  It seems like turning this construct into memcpy as an optimization or part of the back-end lowering might be a better long-term approach.</span></div>
<div><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);"><br>
</span></div>
<div><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">I filed this as bug #21671 in bugzilla.</span></div>
<div><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);"><br>
</span></div>
<div><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">Let me know if you'd like more information or if I can help come up with a fix.  (I'm not familiar at all with the backend so I'd need
 some guidance to be of much help.)</span></div>
<div><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);"><br>
Thanks,</span></div>
<div><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; background-color: rgb(255, 255, 255);">  Dale Martin</span></div>
</body>
</html>