[DAGCombiner] restrict (float)((int) f) --> ftrunc with no-signed-zeros
authorSanjay Patel <spatel@rotateright.com>
Wed, 27 Jun 2018 18:16:40 +0000 (18:16 +0000)
committerSanjay Patel <spatel@rotateright.com>
Wed, 27 Jun 2018 18:16:40 +0000 (18:16 +0000)
commitd052de856d83095bf687755fb0c7c47e916956c8
treef386aa2189c05ee1d68b025e95dea63eb6e82f7e
parent7e7b13d016f6f216c83dde5b925a937ef4cf3072
[DAGCombiner] restrict (float)((int) f) --> ftrunc with no-signed-zeros

As noted in the 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.

Differential Revision: https://reviews.llvm.org/D48085

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