On Wed, Sep 24, 2025 at 09:58:38AM +0530, Surya Kumari Jangala wrote:
> 
> 
> On 31/07/25 11:55 am, Michael Meissner wrote:
> > I have rewritten this page, removing the 'ordered' terminology in the
> > coomit messages and comments that was a problem.
> > 
> > I have also rewritten the patch to hopefully make it easier to
> > understand.
> > 
> > I have built it on both big endian and little endian servers with no
> > regressions.
> > 
> > 
> > Proposed commit message follows:
> > 
> > In bug PR target/118541 on power9, power10, and power11 systems, for the
> > function:
> > 
> >         extern double __ieee754_acos (double);
> > 
> >         double
> >         __acospi (double x)
> >         {
> >           double ret = __ieee754_acos (x) / 3.14;
> >           return __builtin_isgreater (ret, 1.0) ? 1.0 : ret;
> >         }
> > 
> > GCC currently generates the following code:
> > 
> >         Power9                          Power10 and Power11
> >         ======                          ===================
> >         bl __ieee754_acos               bl __ieee754_acos@notoc
> >         nop                             plfd 0,.LC0@pcrel
> >         addis 9,2,.LC2@toc@ha           xxspltidp 12,1065353216
> >         addi 1,1,32                     addi 1,1,32
> >         lfd 0,.LC2@toc@l(9)             ld 0,16(1)
> >         addis 9,2,.LC0@toc@ha           fdiv 0,1,0
> >         ld 0,16(1)                      mtlr 0
> >         lfd 12,.LC0@toc@l(9)            xscmpgtdp 1,0,12
> >         fdiv 0,1,0                      xxsel 1,0,12,1
> >         mtlr 0                          blr
> >         xscmpgtdp 1,0,12
> >         xxsel 1,0,12,1
> >         blr
> > 
> > This is because ifcvt.cc optimizes the conditional floating point move to 
> > use the
> > XSCMPGTDP instruction.
> > 
> > However, the XSCMPGTDP instruction will generate an interrupt if one of the
> > arguments is a signalling NaN and signalling NaNs can generate an interrupt.
> > The IEEE comparison functions (isgreater, etc.) require that the comparison 
> > not
> > raise an interrupt.
> > 
> > The following patch changes the PowerPC back end so that ifcvt.cc will not 
> > change
> > the if/then test and move into a conditional move if the comparison is one 
> > of
> > the comparisons that do not raise an error with signalling NaNs and -Ofast 
> > is
> > not used.  If a normal comparison is used or -Ofast is used, GCC will 
> > continue
> > to generate XSCMPGTDP and XXSEL.
> 
> The isgreater() builtin is not supposed to set floating point exceptions,
> irrespective of which compilation flags are used. So, even if -Ofast is used 
> or
> -ffinite-math-only is used, isgreater() should not set floating point 
> exceptions.
> Using XSCMPGTDP will end up throwing exceptions if at least one of the 
> operand is 
> a qNaN or an sNaN.

The code to convert isgreater to > occurs in the machine independent
portion of the compiler if -Ofast is used.  I.e. there is nothing that
can be done within the PowerPC backend because it has been eliminated
by the other code.

-- 
Michael Meissner, IBM
PO Box 98, Ayer, Massachusetts, USA, 01432
email: [email protected]

Reply via email to