From 25feae555d7c50c35a156373fa79ce50453746fd Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 28 Jan 2008 00:58:18 +0000 Subject: [PATCH] Fix PR1932 by disabling an xform invalid for fdiv. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@46429 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../Scalar/InstructionCombining.cpp | 19 ++++++++++--------- .../InstCombine/2008-01-27-FloatSelect.ll | 7 +++++++ 2 files changed, 17 insertions(+), 9 deletions(-) create mode 100644 test/Transforms/InstCombine/2008-01-27-FloatSelect.ll diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 49f1c45f395..5ba48572a5d 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -2494,14 +2494,15 @@ Instruction *InstCombiner::commonDivTransforms(BinaryOperator &I) { if (isa(Op1)) return ReplaceInstUsesWith(I, Op1); - // Handle cases involving: div X, (select Cond, Y, Z) + // Handle cases involving: [su]div X, (select Cond, Y, Z) + // This does not apply for fdiv. if (SelectInst *SI = dyn_cast(Op1)) { - // div X, (Cond ? 0 : Y) -> div X, Y. If the div and the select are in the - // same basic block, then we replace the select with Y, and the condition - // of the select with false (if the cond value is in the same BB). If the - // select has uses other than the div, this allows them to be simplified - // also. Note that div X, Y is just as good as div X, 0 (undef) - if (Constant *ST = dyn_cast(SI->getOperand(1))) + // [su]div X, (Cond ? 0 : Y) -> div X, Y. If the div and the select are in + // the same basic block, then we replace the select with Y, and the + // condition of the select with false (if the cond value is in the same BB). + // If the select has uses other than the div, this allows them to be + // simplified also. Note that div X, Y is just as good as div X, 0 (undef) + if (ConstantInt *ST = dyn_cast(SI->getOperand(1))) if (ST->isNullValue()) { Instruction *CondI = dyn_cast(SI->getOperand(0)); if (CondI && CondI->getParent() == I.getParent()) @@ -2513,8 +2514,8 @@ Instruction *InstCombiner::commonDivTransforms(BinaryOperator &I) { return &I; } - // Likewise for: div X, (Cond ? Y : 0) -> div X, Y - if (Constant *ST = dyn_cast(SI->getOperand(2))) + // Likewise for: [su]div X, (Cond ? Y : 0) -> div X, Y + if (ConstantInt *ST = dyn_cast(SI->getOperand(2))) if (ST->isNullValue()) { Instruction *CondI = dyn_cast(SI->getOperand(0)); if (CondI && CondI->getParent() == I.getParent()) diff --git a/test/Transforms/InstCombine/2008-01-27-FloatSelect.ll b/test/Transforms/InstCombine/2008-01-27-FloatSelect.ll new file mode 100644 index 00000000000..346f90f8293 --- /dev/null +++ b/test/Transforms/InstCombine/2008-01-27-FloatSelect.ll @@ -0,0 +1,7 @@ +; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep select + +define double @fold(i1 %a, double %b) { +%s = select i1 %a, double 0., double 1. +%c = fdiv double %b, %s +ret double %c +} -- 2.34.1