arsenm wrote:

I've manually gone through the evaluation of the failing example value and I 
can't see how it's the fault of the code. This smells like a codegen bug:

The correct result is threepiby4, the reported failing value is pi. For this to 
have produced pi, `y == 0.0f` would have to incorrectly evaluate as true. 

```
_CLC_OVERLOAD _CLC_CONST _CLC_DEF __CLC_FLOATN __clc_atan2(__CLC_FLOATN y, // 
-0x1.fffffep+127
                                                           __CLC_FLOATN x) {  
// -0x1.fffffep+127
  const __CLC_FLOATN pi = 0x1.921fb6p+1f; // returned pi
  const __CLC_FLOATN piby2 = 0x1.921fb6p+0f;
  const __CLC_FLOATN piby4 = 0x1.921fb6p-1f;
  const __CLC_FLOATN threepiby4 = 0x1.2d97c8p+1f; // correct result

  __CLC_FLOATN ax = __clc_fabs(x); // 0x1.fffffep+127f
  __CLC_FLOATN ay = __clc_fabs(y); // 0x1.fffffep+127f
  __CLC_FLOATN v = __clc_fmin(ax, ay); // 0x1.fffffep+127f
  __CLC_FLOATN u = __clc_fmax(ax, ay); // 0x1.fffffep+127f

  __CLC_FLOATN vbyu = v / u; // 1.0f

  __CLC_FLOATN a = __clc_atan_reduced(vbyu); // clc_atan_reduced(1.0) = 
0x1.921fb6p-1f == piby4

  __CLC_FLOATN t = piby2 - a; // 0x1.921fb6p+0f - 0x1.921fb6p-1f = 
0x1.921fb6p-1f = piby4
  a = ay > ax ? t : a; // ax == ay ? piby4 : piby4
  t = pi - a; // pi - piby4 = 0x1.2d97c8p+1f = threepiby4
  a = x < 0.0f ? t : a; // true, threepiby4

  t = __clc_signbit(x) ? pi : 0.0f; // true => pi
  a = y == 0.0f ? t : a; // y == 0.0f ? pi : threebipi4

  // x and y are +- Inf
  t = x < 0.0f ? threepiby4 : piby4; // threebipy4
  a = (__clc_isinf(x) & __clc_isinf(y)) ? t : a;

  // x or y is NaN
  a = __clc_isunordered(x, y) ? FLT_NAN : a;

  return __clc_copysign(a, y);
}

```

The

https://github.com/llvm/llvm-project/pull/188706
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to