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

Cameron McInally via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 10 06:30:18 PDT 2019


cameron.mcinally created this revision.
cameron.mcinally added reviewers: spatel, arsenm, kpn, andrew.w.kaylor, craig.topper.
Herald added subscribers: llvm-commits, hiraditya, wdng.
Herald added a project: LLVM.

This is essentially the same direction as D61693 <https://reviews.llvm.org/D61693>, but might be easier to review...

Create InstCombine::visitFNeg(...) with a call to InstSimplify to do the heavy lifting. More transforms will need to be copied over from InstCombine::visitFSub(...) in future patches.


Repository:
  rL LLVM

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.199010.patch
Type: text/x-patch
Size: 1894 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190510/9468cc7a/attachment.bin>


More information about the llvm-commits mailing list