[PATCH] D48085: [DAGCombiner] restrict (float)((int) f) --> ftrunc with no-signed-zeros

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 12 10:39:49 PDT 2018


spatel created this revision.
spatel added reviewers: rdhindsa, nemanjai, hans, dmgreen, scanon, echristo, thakis, efriedma, craig.topper, RKSimon.
Herald added a subscriber: mcrosier.
Herald added a reviewer: javed.absar.

As noted in the https://reviews.llvm.org/D44909 review, the transform from (fptosi+sitofp) to ftrunc can produce -0.0 where the original code does not:

  #include <stdio.h>
    
  int main(int argc) {
    float x;
    x = -0.8 * argc;
    printf("%f\n", (float)((int)x));
    return 0;
  }



  $ clang -O0 -mavx fp.c ; ./a.out 
  0.000000
  $ clang -O1 -mavx fp.c ; ./a.out 
  -0.000000

Ideally, we'd use IR/node flags to predicate the transform, but the IR parser doesn't currently allow fast-math-flags on the cast instructions. So for now, just use the function attribute that corresponds to clang's "-fno-signed-zeros" option.


https://reviews.llvm.org/D48085

Files:
  lib/CodeGen/SelectionDAG/DAGCombiner.cpp
  test/CodeGen/AArch64/ftrunc.ll
  test/CodeGen/PowerPC/fp-int128-fp-combine.ll
  test/CodeGen/PowerPC/fp-to-int-to-fp.ll
  test/CodeGen/PowerPC/ftrunc-vec.ll
  test/CodeGen/PowerPC/no-extra-fp-conv-ldst.ll
  test/CodeGen/X86/2011-10-19-widen_vselect.ll
  test/CodeGen/X86/avx-cvttp2si.ll
  test/CodeGen/X86/ftrunc.ll
  test/CodeGen/X86/sse-cvttp2si.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48085.150979.patch
Type: text/x-patch
Size: 15525 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180612/45613773/attachment.bin>


More information about the llvm-commits mailing list