<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span style="font-family: Calibri, sans-serif; font-size: 11pt;" class=""> </span><br class=""><div><blockquote type="cite" class=""><div class="WordSection1" style="page: WordSection1; font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-size: 11pt; font-family: Calibri, sans-serif;" class="">Regarding SDAG, and given that poison is already there, we would need to adopt a similar solution to the IR.  Maybe right now we can get away with it because nsw is not exploited significantly (as you say).  Just because there</span><span style="font-size: 11pt;" class="">’</span><span style="font-size: 11pt; font-family: Calibri, sans-serif;" class="">s no explicit poison in SDAG, just having nsw is sufficient to cause miscompilations when combined with other transformations.<o:p class=""></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-size: 11pt; font-family: Calibri, sans-serif;" class="">See, for example, this bug report for InstCombine regarding select+nsw:<span class="Apple-converted-space"> </span><font color="#800080" class=""><u class=""><a href="https://bugs.llvm.org/show_bug.cgi?id=31633" class="">https://bugs.llvm.org/show_bug.cgi?id=31633</a></u></font></span></div></div></blockquote><div><br class=""></div>Poison/Undef at the CodeGen level is a very interesting discussion! I don't think there is any documentation about posion/undef at the CodeGen level and I haven't discussed this much with others, so I'd like to hear further feedback:</div><div><br class=""></div><div>- I think we should not introduce a notion of poison (which I would call "delayed UB") at the SelectionDAG/CodeGen level[1]</div><div>- Instructions either produce UB immediately, so while there are nsw/nuw flags on SelectionDAG arithmetic operatiosn I think we can only assume that they produce a target specific value on overflow, but not arbitrary behavior. Instructions that can produce UB should marked "hasSideEffect" and code motion around it be limited.</div><div>- Typical optimization scenarios like establishing loop trip count bounds for which poison/UB is helpful should not matter for CodeGen.</div><div>- I don't have any evidence that optimizations in CodeGen require a model of poison to work. If someone can given me a counter example then I'd be hard pressed to disable the optimization in MI and push it towards the IR level.</div><div><br class=""></div><div>- Matthias</div></body></html>