llvm.org GIT mirror llvm / 4ca7913
add support for pattern matching 'neg' git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50883 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 12 years ago
2 changed file(s) with 31 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
235235
236236 /// swapOperands - Exchange the two operands to this instruction.
237237 /// This instruction is safe to use on any binary instruction and
238 /// does not modify the semantics of the instruction. If the
239 /// instruction is order dependent (SetLT f.e.) the opcode is
240 /// changed. If the instruction cannot be reversed (ie, it's a Div),
241 /// then return true.
238 /// does not modify the semantics of the instruction. If the instruction
239 /// cannot be reversed (ie, it's a Div), then return true.
242240 ///
243241 bool swapOperands();
244242
384384 inline not_match m_Not(const LHS &L) { return L; }
385385
386386
387 template
388 struct neg_match {
389 LHS_t L;
390
391 neg_match(const LHS_t &LHS) : L(LHS) {}
392
393 template
394 bool match(OpTy *V) {
395 if (Instruction *I = dyn_cast(V))
396 if (I->getOpcode() == Instruction::Sub)
397 return matchIfNeg(I->getOperand(0), I->getOperand(1));
398 if (ConstantExpr *CE = dyn_cast(V))
399 if (CE->getOpcode() == Instruction::Sub)
400 return matchIfNeg(CE->getOperand(0), CE->getOperand(1));
401 if (ConstantInt *CI = dyn_cast(V))
402 return L.match(ConstantExpr::getNeg(CI));
403 return false;
404 }
405 private:
406 bool matchIfNeg(Value *LHS, Value *RHS) {
407 return LHS == ConstantExpr::getZeroValueForNegationExpr(LHS->getType()) &&
408 L.match(RHS);
409 }
410 };
411
412 template
413 inline neg_match m_Neg(const LHS &L) { return L; }
414
415
387416 //===----------------------------------------------------------------------===//
388417 // Matchers for control flow
389418 //