[LLVMdev] [RFC] Extend LLVM IR to express "fast-math" at a per-instruction level

Michael Ilseman milseman at apple.com
Fri Nov 2 09:53:58 PDT 2012


On Nov 1, 2012, at 6:41 PM, Krzysztof Parzyszek <kparzysz at codeaurora.org> wrote:

> On 11/1/2012 6:38 PM, Michael Ilseman wrote:
>> 
>> On Nov 1, 2012, at 3:08 PM, Dan Gohman <dan433584 at gmail.com
>> <mailto:dan433584 at gmail.com>> wrote:
>>> 
>>> If the "optimizer" may truly ignore the possibility of NaNs under the
>>> N flag, this would seem to be ok. However, a trap is outside the
>>> boundaries of "undefined result". So, which half is right?
>>> 
>> 
>> That makes sense, I was thinking of things only in terms of the
>> optimizer and not in terms of instruction selection. Which do you think
>> is better, Undefined Behavior or that instruction selection should
>> disregard those bits? I'd lean towards undefined behavior, but I don't
>> have a good feel for LLVM's overall design for undefined behavior,
>> poison values, etc.
> 
> I still don't understand Dan's concerns, but a target that traps on a quiet NaN is not IEEE compliant.  IEEE754 requires that quiet NaNs get propagated through operands to the results without causing exceptions.
> 

I think Dan was making two points with his example. Dan, correct me if I misrepresent your example, but image a situation where a target has two instructions to choose between in order to perform the operation. The first is IEEE compliant, but the second isn't compliant in how it operates over NaNs (quiet or otherwise). For whatever reason, the second is preferred when we know inputs are not NaN.

The first point is that I didn't specify if the N bit would allow the target to choose the non-compliant operation.

The second point is that my specifying "undefined value" isn't enough. What if the non-compliant instruction's behavior on NaN was to trap. It's not just an invalid/random bit pattern, but actual behavioral differences.

My question is whether to approach this by saying that the flags are for the optimizer only, and targets must ignore them, or to say that targets are free to use them and the operation has undefined behavior over, e.g., NaN.

> -Krzysztof
> 
> -- 
> Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev




More information about the llvm-dev mailing list