From: Cameron McInally Date: Fri, 10 May 2019 20:01:04 +0000 (+0000) Subject: Add InstCombine::visitFNeg(...) X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7b1463b708979d11a0ee349f1f8aa08e789dbd70;p=llvm Add InstCombine::visitFNeg(...) Differential Revision: https://reviews.llvm.org/D61784 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360461 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/lib/Transforms/InstCombine/InstCombineAddSub.cpp index a2313809d28..5f5a94e4b25 100644 --- a/lib/Transforms/InstCombine/InstCombineAddSub.cpp +++ b/lib/Transforms/InstCombine/InstCombineAddSub.cpp @@ -1821,6 +1821,15 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) { return Changed ? &I : nullptr; } +Instruction *InstCombiner::visitFNeg(UnaryOperator &I) { + if (Value *V = SimplifyFNegInst(I.getOperand(0), I.getFastMathFlags(), + SQ.getWithInstruction(&I))) + return replaceInstUsesWith(I, V); + + return nullptr; +} + + Instruction *InstCombiner::visitFSub(BinaryOperator &I) { if (Value *V = SimplifyFSubInst(I.getOperand(0), I.getOperand(1), I.getFastMathFlags(), diff --git a/lib/Transforms/InstCombine/InstCombineInternal.h b/lib/Transforms/InstCombine/InstCombineInternal.h index 27b8ea81ec0..c34a71a2251 100644 --- a/lib/Transforms/InstCombine/InstCombineInternal.h +++ b/lib/Transforms/InstCombine/InstCombineInternal.h @@ -347,6 +347,7 @@ public: // I - Change was made, I is still valid, I may be dead though // otherwise - Change was made, replace I with returned instruction // + Instruction *visitFNeg(UnaryOperator &I); Instruction *visitAdd(BinaryOperator &I); Instruction *visitFAdd(BinaryOperator &I); Value *OptimizePointerDifference(Value *LHS, Value *RHS, Type *Ty); diff --git a/test/Transforms/InstCombine/fneg.ll b/test/Transforms/InstCombine/fneg.ll index 6c1fb119d78..2fdb1947912 100644 --- a/test/Transforms/InstCombine/fneg.ll +++ b/test/Transforms/InstCombine/fneg.ll @@ -6,9 +6,7 @@ declare void @use(float) define float @fneg_fneg(float %a) { ; ; CHECK-LABEL: @fneg_fneg( -; CHECK-NEXT: [[F:%.*]] = fneg float [[A:%.*]] -; CHECK-NEXT: [[R:%.*]] = fneg float [[F]] -; CHECK-NEXT: ret float [[R]] +; CHECK-NEXT: ret float [[A:%.*]] ; %f = fneg float %a %r = fneg float %f