[PATCH] D61784: Simple attempt at adding InstCombine::visitFNeg(...)

Cameron McInally via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 10 13:02:40 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rGe75412ab4748: Add InstCombine::visitFNeg(...) (authored by cameron.mcinally).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61784/new/

https://reviews.llvm.org/D61784

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


Index: llvm/test/Transforms/InstCombine/fneg.ll
===================================================================
--- llvm/test/Transforms/InstCombine/fneg.ll
+++ llvm/test/Transforms/InstCombine/fneg.ll
@@ -6,9 +6,7 @@
 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
Index: llvm/lib/Transforms/InstCombine/InstCombineInternal.h
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineInternal.h
+++ llvm/lib/Transforms/InstCombine/InstCombineInternal.h
@@ -347,6 +347,7 @@
   //     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: llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -1821,6 +1821,15 @@
   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(),


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61784.199065.patch
Type: text/x-patch
Size: 1894 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190510/fdaa42db/attachment.bin>


More information about the llvm-commits mailing list