[PATCH] D24033: Convert clamp into fmaxnum/fminnum pairs.

Kevin Hu via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 30 08:49:12 PDT 2016


hxy9243 created this revision.
hxy9243 added reviewers: sebpop, majnemer, wmi.
hxy9243 added subscribers: hiraditya, llvm-commits.
hxy9243 set the repository for this revision to rL LLVM.

This patch converts clamp at DAG level in DAGCombiner.cpp. For example, the following code:

```
float clamp(float a)                                                                                                                                                                       
{                                                                                                                                                                                             
  const float b = 255.0;                                                                                                                                                                      
  const float c = 0.0;                                                                                                                                                                        
                                                                                                                                                                                              
  if(b < a)                                                                                                                                                                                   
    return b;                                                                                                                                                                                 
  if(a < c)                                                                                                                                                                                   
    return c;                                                                                                                                                                                 
                                                                                                                                                                                              
  return a;                                                                                                                                                                                   
}
```

could be compiled:


```
clamp:                                  // @clamp
// BB#0:                                // %entry
        adrp    x8, .LCPI0_0
        ldr     s1, [x8, :lo12:.LCPI0_0]
        fmov    s2, wzr
        fmaxnm  s0, s0, s2
        fminnm  s0, s0, s1
        ret
```

I work with @hiraditya on this patch.

Repository:
  rL LLVM

https://reviews.llvm.org/D24033

Files:
  llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
  llvm/test/CodeGen/AArch64/aarch64-DAGCombine-fminmax.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24033.69695.patch
Type: text/x-patch
Size: 6518 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160830/8511dc3d/attachment.bin>


More information about the llvm-commits mailing list