<div dir="ltr">Hey Jeffrey,<div><br></div><div>Thanks for the suggestion. A few comments...<div class="gmail_extra"><br><div class="gmail_quote">On Sun, Apr 7, 2013 at 12:31 PM, Jeffrey Yasskin <span dir="ltr"><<a href="mailto:jyasskin@googlers.com" target="_blank">jyasskin@googlers.com</a>></span> wrote:</div>
<div class="gmail_quote">...<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">If you can find a way to implement -fsanitize=undefined to use the FP<br>
trap instead of a branch when checking floating division by 0, I<br>
suspect such a patch would stand a good chance of being accepted.<br>
(Although I'm not intimately familiar with the implementation, so<br>
there could be some subtlety that would prevent it.) </blockquote><div><br></div><div style>This would work well for the constant expression division case, since the division by zero expression would be folded away leaving only a call to trap. The performance penalty for using -fsanitize on other non-constant division expressions is still unclear to me; and concerning.</div>
<div style><br></div><div style>Although, I've been contemplating x86-64's behaviour for this case when floating point traps are disabled. Ideally, the compiler should preserve that behaviour, which might make this software implementation messy. Especially if different processors have different implementations. The simplest solution... let the hardware behave as it should.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">You might need to<br>
do this in the processor-specific backend to avoid other<br>
undefined-behavior-based optimizations—that is, recognize "if (x == 0)<br>
goto err_handler; else y/x;" and replace it with<br>
"register-pc-in-fp-handler-map(); turn-on-fp-traps(); y/x;".<br></blockquote><div><br></div><div style>I believe that the constant folder would remove the constant division by zero and conditional before the backend could have its say. We would be left with only the jump to the error handler. That may complicate things.</div>
<div style><br></div><div style>Please correct me if I am misunderstanding.</div><div style><br></div><div style>Thanks again,</div><div style>Cameron</div></div></div></div></div>