diff options
| author | Stephen Lin <stephenwlin@gmail.com> | 2013-07-20 07:13:13 +0000 | 
|---|---|---|
| committer | Stephen Lin <stephenwlin@gmail.com> | 2013-07-20 07:13:13 +0000 | 
| commit | a9b57f6bea970d29f027ed01ab8c86ad7992c757 (patch) | |
| tree | 53ee7a01f4eb80f04f09b80d52670b6069bb85bf /llvm/lib/Transforms | |
| parent | 727aa349ad3c49d590693961ae0d0dfb39d95089 (diff) | |
| download | bcm5719-llvm-a9b57f6bea970d29f027ed01ab8c86ad7992c757.tar.gz bcm5719-llvm-a9b57f6bea970d29f027ed01ab8c86ad7992c757.zip | |
InstCombine: call FoldOpIntoSelect for all floating binops, not just fmul
llvm-svn: 186759
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp | 17 | ||||
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | 9 | 
2 files changed, 23 insertions, 3 deletions
| diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp index fecbd5c3010..0aa301bc7a8 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp @@ -1186,9 +1186,15 @@ Instruction *InstCombiner::visitFAdd(BinaryOperator &I) {    if (Value *V = SimplifyFAddInst(LHS, RHS, I.getFastMathFlags(), TD))      return ReplaceInstUsesWith(I, V); -  if (isa<Constant>(RHS) && isa<PHINode>(LHS)) -    if (Instruction *NV = FoldOpIntoPhi(I)) -      return NV; +  if (isa<Constant>(RHS)) { +    if (isa<PHINode>(LHS)) +      if (Instruction *NV = FoldOpIntoPhi(I)) +        return NV; + +    if (SelectInst *SI = dyn_cast<SelectInst>(LHS)) +      if (Instruction *NV = FoldOpIntoSelect(I, SI)) +        return NV; +  }    // -A + B  -->  B - A    // -A + -B  -->  -(A + B) @@ -1517,6 +1523,11 @@ Instruction *InstCombiner::visitFSub(BinaryOperator &I) {    if (Value *V = SimplifyFSubInst(Op0, Op1, I.getFastMathFlags(), TD))      return ReplaceInstUsesWith(I, V); +  if (isa<Constant>(Op0)) +    if (SelectInst *SI = dyn_cast<SelectInst>(Op1)) +      if (Instruction *NV = FoldOpIntoSelect(I, SI)) +        return NV; +    // If this is a 'B = x-(-A)', change to B = x+A...    if (Value *V = dyn_castFNegVal(Op1))      return BinaryOperator::CreateFAdd(Op0, V); diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp index c3621af638b..780e0eb0dcb 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp @@ -990,10 +990,19 @@ Instruction *InstCombiner::visitFDiv(BinaryOperator &I) {    if (Value *V = SimplifyFDivInst(Op0, Op1, TD))      return ReplaceInstUsesWith(I, V); +  if (isa<Constant>(Op0)) +    if (SelectInst *SI = dyn_cast<SelectInst>(Op1)) +      if (Instruction *R = FoldOpIntoSelect(I, SI)) +        return R; +    bool AllowReassociate = I.hasUnsafeAlgebra();    bool AllowReciprocal = I.hasAllowReciprocal();    if (ConstantFP *Op1C = dyn_cast<ConstantFP>(Op1)) { +    if (SelectInst *SI = dyn_cast<SelectInst>(Op0)) +      if (Instruction *R = FoldOpIntoSelect(I, SI)) +        return R; +      if (AllowReassociate) {        ConstantFP *C1 = 0;        ConstantFP *C2 = Op1C; | 

