From 07076cfdf63dc0599cc5f1910b825404f53a8053 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Tue, 23 Oct 2018 17:06:03 +0000 Subject: [PATCH] [IR] remove fake binop queries for not/neg The initial motivation is that we want to remove the fneg API because that would silently fail if we add an actual fneg instruction to IR. The same would be true for the integer ops, so we might as well get rid of these too. We have a newer 'match' API that makes checking for these patterns simpler. It also works with vectors that may include undef elements in constants. If any out-of-tree users need updating, they can model their code changes on these commits: rL345050 rL345043 rL345042 rL345041 rL345036 rL345030 llvm-svn: 345052 --- llvm/include/llvm/IR/InstrTypes.h | 13 ++--------- llvm/lib/IR/Instructions.cpp | 39 ------------------------------- 2 files changed, 2 insertions(+), 50 deletions(-) diff --git a/llvm/include/llvm/IR/InstrTypes.h b/llvm/include/llvm/IR/InstrTypes.h index e42bfc3afce0..4487768e6c6f 100644 --- a/llvm/include/llvm/IR/InstrTypes.h +++ b/llvm/include/llvm/IR/InstrTypes.h @@ -308,21 +308,12 @@ public: static BinaryOperator *CreateNot(Value *Op, const Twine &Name, BasicBlock *InsertAtEnd); - /// Check if the given Value is a NEG, FNeg, or NOT instruction. - /// - static bool isNeg(const Value *V); + /// Check if the given Value is an FNeg instruction. static bool isFNeg(const Value *V, bool IgnoreZeroSign=false); - static bool isNot(const Value *V); - /// Helper functions to extract the unary argument of a NEG, FNEG or NOT - /// operation implemented via Sub, FSub, or Xor. - /// - static const Value *getNegArgument(const Value *BinOp); - static Value *getNegArgument( Value *BinOp); + /// Helper functions to extract the unary argument of an FNeg. static const Value *getFNegArgument(const Value *BinOp); static Value *getFNegArgument( Value *BinOp); - static const Value *getNotArgument(const Value *BinOp); - static Value *getNotArgument( Value *BinOp); BinaryOps getOpcode() const { return static_cast(Instruction::getOpcode()); diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp index e1d1c0f2a6b2..2a188b77679c 100644 --- a/llvm/lib/IR/Instructions.cpp +++ b/llvm/lib/IR/Instructions.cpp @@ -2116,14 +2116,6 @@ static inline bool isConstantAllOnes(const Value *V) { return false; } -bool BinaryOperator::isNeg(const Value *V) { - if (const BinaryOperator *Bop = dyn_cast(V)) - if (Bop->getOpcode() == Instruction::Sub) - if (Constant *C = dyn_cast(Bop->getOperand(0))) - return C->isNegativeZeroValue(); - return false; -} - bool BinaryOperator::isFNeg(const Value *V, bool IgnoreZeroSign) { if (const BinaryOperator *Bop = dyn_cast(V)) if (Bop->getOpcode() == Instruction::FSub) @@ -2135,22 +2127,6 @@ bool BinaryOperator::isFNeg(const Value *V, bool IgnoreZeroSign) { return false; } -bool BinaryOperator::isNot(const Value *V) { - if (const BinaryOperator *Bop = dyn_cast(V)) - return (Bop->getOpcode() == Instruction::Xor && - (isConstantAllOnes(Bop->getOperand(1)) || - isConstantAllOnes(Bop->getOperand(0)))); - return false; -} - -Value *BinaryOperator::getNegArgument(Value *BinOp) { - return cast(BinOp)->getOperand(1); -} - -const Value *BinaryOperator::getNegArgument(const Value *BinOp) { - return getNegArgument(const_cast(BinOp)); -} - Value *BinaryOperator::getFNegArgument(Value *BinOp) { return cast(BinOp)->getOperand(1); } @@ -2159,21 +2135,6 @@ const Value *BinaryOperator::getFNegArgument(const Value *BinOp) { return getFNegArgument(const_cast(BinOp)); } -Value *BinaryOperator::getNotArgument(Value *BinOp) { - assert(isNot(BinOp) && "getNotArgument on non-'not' instruction!"); - BinaryOperator *BO = cast(BinOp); - Value *Op0 = BO->getOperand(0); - Value *Op1 = BO->getOperand(1); - if (isConstantAllOnes(Op0)) return Op1; - - assert(isConstantAllOnes(Op1)); - return Op0; -} - -const Value *BinaryOperator::getNotArgument(const Value *BinOp) { - return getNotArgument(const_cast(BinOp)); -} - // Exchange the two operands to this instruction. This instruction is safe to // use on any binary instruction and does not modify the semantics of the // instruction. If the instruction is order-dependent (SetLT f.e.), the opcode