fix an invisible bug when combining repeated FP divisors
authorSanjay Patel <spatel@rotateright.com>
Thu, 9 Jul 2015 17:28:37 +0000 (17:28 +0000)
committerSanjay Patel <spatel@rotateright.com>
Thu, 9 Jul 2015 17:28:37 +0000 (17:28 +0000)
commitdc219dddde93aee367fe7982f2ceeb26528f06dc
tree7e4d5f055055564d6a8777b6d6e2a63511242d82
parentc014920a89f39e9606e42ced600ef70caaca64c1
fix an invisible bug when combining repeated FP divisors

This patch fixes bugs that were exposed by the addition of fast-math-flags in the DAG:
r237046 ( http://reviews.llvm.org/rL237046 ):

1. When replacing a division node, it's not enough to RAUW.
   We should call CombineTo() to delete dead nodes and combine again.
2. Because we are changing the DAG, we can't return an empty SDValue
   after the transform. As the code comments say:

    Visitation implementation - Implement dag node combining for different node types.
    The semantics are as follows: Return Value:
      SDValue.getNode() == 0 - No change was made
      SDValue.getNode() == N - N was replaced, is dead and has been handled.
      otherwise - N should be replaced by the returned Operand.

The new test case shows no difference with or without this patch, but it will crash if
we re-apply r237046 or enable FMF via the current -enable-fmf-dag cl::opt.

Differential Revision: http://reviews.llvm.org/D9893

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241826 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/SelectionDAG/DAGCombiner.cpp
test/CodeGen/X86/fdiv-combine.ll