<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">On Fri, Jun 14, 2019 at 7:10 PM Chris Lattner <<a href="mailto:clattner@nondot.org">clattner@nondot.org</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space"><br><div><br><blockquote type="cite"><div>On Jun 14, 2019, at 4:06 PM, Cameron McInally <<a href="mailto:cameron.mcinally@nyu.edu" target="_blank">cameron.mcinally@nyu.edu</a>> wrote:</div><br class="gmail-m_-1510330375827564095Apple-interchange-newline"><div><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jun 14, 2019 at 6:58 PM Chris Lattner via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space"><br><div><br><blockquote type="cite"><div>On Jun 14, 2019, at 3:24 PM, Eli Friedman via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="gmail-m_-1510330375827564095gmail-m_-4692219112205293189Apple-interchange-newline"><div><div class="gmail-m_-1510330375827564095gmail-m_-4692219112205293189WordSection1" style="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;text-decoration:none"><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif">See<span class="gmail-m_-1510330375827564095gmail-m_-4692219112205293189Apple-converted-space"> </span><a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__reviews.llvm.org_D63036&d=DwMFaQ&c=slrrB7dE8n7gBJbeO0g-IQ&r=O_4M49EtSpZ_-BQYeigzGv0P4__noMcSu2RYEjS1vKs&m=HPH8LbjOYmP3G9p6HJYKLtOFGQQJ0aWeEc7QU46PkOw&s=Q-PK-STEJTkFgcTQeOjIR7RY4e_iIHz191Qk_8syQlA&e=" style="color:rgb(149,79,114);text-decoration:underline" target="_blank">https://reviews.llvm.org/D63036</a><span class="gmail-m_-1510330375827564095gmail-m_-4692219112205293189Apple-converted-space"> </span>for the full patch and description. Essentially, the Constant::canTrap API is going away.  To make this work, the semantics of division and remainder constant expressions are changing slightly, so division by zero produces poison, not undefined behavior.  (The corresponding instructions still have undefined behavior.)  This change should make writing and understanding IR optimizations easier.</div></div></div></blockquote><br></div><div>Is anyone interested and willing to make a more profound change to llvm’s constants?  We should really remove all the trapping operators.  The only reason they exist in the first place is to allow use of Constant::get() as a high level constant folding API.  We could replace that, eliminate the trapping operators, and thus eliminate a ton of complexity and bugs…</div></div></blockquote><div><br></div><div>Hi Chris,</div><div><br></div><div>If I'm understanding your proposal correctly, the constrained FP intrinsic work could make use of that code -- in the future. Eventually we'll want to optimize the constrained FP intrinsics and being able to constant fold non-trapping instructions is important.</div></div></div></div></blockquote><br></div><div>Right: in terms of primary constant folding entry points, the ConstExpr::get sort of methods have always been a mistake (and I’ve never gotten around to fixing them).</div></div></blockquote><div><br></div><div>Ok, I think I understand now. So we'd retain the ability to constant fold operations that may trap, possibly returning trap flags, through APFloat. If that's correct, that would work for the constrained FP intrinsics project. No big deal.</div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space"><div>A better thing to do is to make ConstExpr’s have their own enum of “operations”, and make them correspond to the things that show up in a global variable initializer (e.g. relocatable expressions). There is no reason for constant expressions to mirror the instruction enum, and there is lots of harm caused by it.</div></div></blockquote><div><br></div><div>You may have lost me here, but that's ok. If you're suggesting not switching on the Instruction OpCodes in ConstantExpr::get(...) et al, to encapsulate the ConstantExpr class, then +1 from me.</div></div></div></div></div></div></div>