<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi,<div><br></div><div>We use to have a design where LegalizeOp did both type legalization and operation legalization.  The problem with that approach was that after type legalization, there were opportunities for dag combiner to cleanup code and if it was one phase, we would miss these optimizations or have to teach legalization the optimizations that dag combiner has.</div><div><br></div><div>Here is a patch for an alternative approach based on using the custom lowering hook. The default widening algorithm doesn't know if an operation doesn't have a vector equivalent nor if the operation can trap since this is target dependent. For these cases, widen will want to scalarize the operation and rebuild the vector and add any undefs at the end for the widen vector.  This avoids generating the operation on undef. The patch adds the custom lowering node hook to Widening in Type Legalization.  In the target machine, for any vector divide/remainder operation that we would need to widen (i.e., vectors of illegal types), we would call the custom widen operation which does the above.  I need to add a few test cases but it does fix the case you gave in your example.  Please let me know what you think.</div><div><br></div><div>-- Mon Ping</div><div><br></div><div></div></body></html>