[PATCH] D50714: [InstCombine] Fold Select with binary op - FP opcodes

Dávid Bolvanský via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 21 07:58:43 PDT 2018


xbolva00 added inline comments.


================
Comment at: lib/Transforms/InstCombine/InstCombineSelect.cpp:72-73
+    IsEq = true;
+  else if (Pred == FCmpInst::FCMP_ONE)
+    IsEq = false;
+  else
----------------
spatel wrote:
> xbolva00 wrote:
> > spatel wrote:
> > > Did you try testing ONE/UNE in alive-fp?
> > ```
> > %A = fcmp one float %x, 0.0
> > %B = fadd nsz float %x, %z
> > %C = select i1 %A, float %B, float %y
> > =>
> > %C = select i1 %A, float %B, float %z
> > ----------                                                                      
> >   %A = fcmp one float %x, 0.0
> >   %B = fadd nsz float %x, %z
> >   %C = select %A, float %B, float %y
> > =>
> >   %C = select %A, float %B, float %z
> > 
> > ERROR: Mismatch in values for float %C                                          
> > 
> > Example:
> > float %x = NaN
> >    i1 %A = 0x0 (0)
> > float %z = 0.0640411376953125*(2**-126)
> > float %B = NaN
> > float %y = 1.00048828125*(2**1)
> > source: 1.00048828125*(2**1)
> > target: 0.0640411376953125*(2**-126)
> > 
> > xbolva00 at xbolva00:~/alive-nj$ ./run.py                               
> > [Reading from terminal...]
> > %A = fcmp une float %x, 0.0
> > %B = fadd nsz float %x, %z
> > %C = select i1 %A, float %B, float %y
> > =>
> > %C = select i1 %A, float %B, float %z
> > ----------                                                                      
> >   %A = fcmp une float %x, 0.0
> >   %B = fadd nsz float %x, %z
> >   %C = select %A, float %B, float %y
> > =>
> >   %C = select %A, float %B, float %z
> > 
> > ERROR: Mismatch in values for float %C                                          
> > 
> > Example:
> > float %x = = +0.0
> >    i1 %A = 0x0 (0)
> > float %z = NaN
> > float %B = NaN
> > float %y = 0.0000002384185791015625*(2**-126)
> > source: 0.0000002384185791015625*(2**-126)
> > target: NaN
> > 
> > ```
> I think you want these tests to use -0.0 because that's the identity constant for fadd.
```
%A = fcmp one float %x, -0.0
%B = fadd nsz float %x, %z
%C = select i1 %A, float %B, float %y
=>
%C = select i1 %A, float %B, float %z
----------                                                                      
  %A = fcmp one float %x, -0.0
  %B = fadd nsz float %x, %z
  %C = select %A, float %B, float %y
=>
  %C = select %A, float %B, float %z

ERROR: Mismatch in values for float %C                                          

Example:
float %x = +0.0
   i1 %A = 0x0 (0)
float %z = -0.504963397979736328125*(2**-126)
float %B = -0.504963397979736328125*(2**-126)
float %y = 1.5*(2**-125)
source: 1.5*(2**-125)
target: -0.504963397979736328125*(2**-126)

%A = fcmp une float %x, -0.0
%B = fadd nsz float %x, %z
%C = select i1 %A, float %B, float %y
=>
%C = select i1 %A, float %B, float %z
----------                                                                      
  %A = fcmp une float %x, -0.0
  %B = fadd nsz float %x, %z
  %C = select %A, float %B, float %y
=>
  %C = select %A, float %B, float %z

ERROR: Mismatch in values for float %C                                          

Example:
float %x = +0.0
   i1 %A = 0x0 (0)
float %z = +oo
float %B = +oo
float %y = -0.03125*(2**-126)
source: -0.03125*(2**-126)
target: +oo

```


https://reviews.llvm.org/D50714





More information about the llvm-commits mailing list