Add InstCombine::visitFNeg(...)
authorCameron McInally <cameron.mcinally@nyu.edu>
Fri, 10 May 2019 20:01:04 +0000 (20:01 +0000)
committerCameron McInally <cameron.mcinally@nyu.edu>
Fri, 10 May 2019 20:01:04 +0000 (20:01 +0000)
Differential Revision: https://reviews.llvm.org/D61784

llvm-svn: 360461

llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
llvm/lib/Transforms/InstCombine/InstCombineInternal.h
llvm/test/Transforms/InstCombine/fneg.ll

index a231380..5f5a94e 100644 (file)
@@ -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(),
index 27b8ea8..c34a71a 100644 (file)
@@ -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);
index 6c1fb11..2fdb194 100644 (file)
@@ -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