Lines Matching full:instruction
1 //===- InstructionSimplify.cpp - Fold instruction operands ----------------===//
52 const Instruction *CxtI;
56 const Instruction *cxti = nullptr)
104 Instruction *I = dyn_cast<Instruction>(V);
124 // Otherwise, if the instruction is in the entry block, and is not an invoke,
141 Instruction::BinaryOps OpcodeToExpand = (Instruction::BinaryOps)OpcToExpand;
156 if ((L == A && R == B) || (Instruction::isCommutative(OpcodeToExpand)
179 if ((L == B && R == C) || (Instruction::isCommutative(OpcodeToExpand)
199 Instruction::BinaryOps Opcode = (Instruction::BinaryOps)Opc;
200 assert(Instruction::isAssociative(Opcode) && "Not an associative operation!");
248 if (!Instruction::isCommutative(Opcode))
293 /// instruction as an operand, try to simplify the binop by seeing whether
306 assert(isa<SelectInst>(RHS) && "No select instruction operand!");
343 Instruction *Simplified = dyn_cast<Instruction>(FV ? FV : TV);
364 /// ThreadCmpOverSelect - In the case of a comparison with a select instruction,
380 assert(isa<SelectInst>(LHS) && "Not comparing with a select instruction!");
447 /// is a PHI instruction, try to simplify the binop by seeing whether evaluating
463 assert(isa<PHINode>(RHS) && "No PHI instruction operand!");
489 /// ThreadCmpOverPHI - In the case of a comparison with a PHI instruction, try
504 assert(isa<PHINode>(LHS) && "Not comparing with a phi instruction!");
535 return ConstantFoldInstOperands(Instruction::Add, CLHS->getType(), Ops,
570 if (Value *V = SimplifyAssociativeBinOp(Instruction::Add, Op0, Op1, Q,
589 const Instruction *CxtI) {
612 // instruction in an unreachable block, which may be on a cycle.
621 } else if (Operator::getOpcode(V) == Instruction::BitCast) {
667 return ConstantFoldInstOperands(Instruction::Sub, CLHS->getType(),
693 if (Value *V = SimplifyBinOp(Instruction::Sub, Y, Z, Q, MaxRecurse-1))
695 if (Value *W = SimplifyBinOp(Instruction::Add, X, V, Q, MaxRecurse-1)) {
701 if (Value *V = SimplifyBinOp(Instruction::Sub, X, Z, Q, MaxRecurse-1))
703 if (Value *W = SimplifyBinOp(Instruction::Add, Y, V, Q, MaxRecurse-1)) {
715 if (Value *V = SimplifyBinOp(Instruction::Sub, X, Y, Q, MaxRecurse-1))
717 if (Value *W = SimplifyBinOp(Instruction::Sub, V, Z, Q, MaxRecurse-1)) {
723 if (Value *V = SimplifyBinOp(Instruction::Sub, X, Z, Q, MaxRecurse-1))
725 if (Value *W = SimplifyBinOp(Instruction::Sub, V, Y, Q, MaxRecurse-1)) {
737 if (Value *V = SimplifyBinOp(Instruction::Sub, Z, X, Q, MaxRecurse-1))
739 if (Value *W = SimplifyBinOp(Instruction::Add, V, Y, Q, MaxRecurse-1)) {
750 if (Value *V = SimplifyBinOp(Instruction::Sub, X, Y, Q, MaxRecurse-1))
782 const Instruction *CxtI) {
794 return ConstantFoldInstOperands(Instruction::FAdd, CLHS->getType(),
820 Instruction *FSub = cast<Instruction>(SubOp);
836 return ConstantFoldInstOperands(Instruction::FSub, CLHS->getType(),
874 return ConstantFoldInstOperands(Instruction::FMul, CLHS->getType(),
900 return ConstantFoldInstOperands(Instruction::Mul, CLHS->getType(),
932 if (Value *V = SimplifyAssociativeBinOp(Instruction::Mul, Op0, Op1, Q,
937 if (Value *V = ExpandBinOp(Instruction::Mul, Op0, Op1, Instruction::Add,
941 // If the operation is with the result of a select instruction, check whether
944 if (Value *V = ThreadBinOpOverSelect(Instruction::Mul, Op0, Op1, Q,
948 // If the operation is with the result of a phi instruction, check whether
951 if (Value *V = ThreadBinOpOverPHI(Instruction::Mul, Op0, Op1, Q,
962 const Instruction *CxtI) {
971 const Instruction *CxtI) {
980 const Instruction *CxtI) {
988 const Instruction *CxtI) {
995 static Value *SimplifyDiv(Instruction::BinaryOps Opcode, Value *Op0, Value *Op1,
1004 bool isSigned = Opcode == Instruction::SDiv;
1064 // If the operation is with the result of a select instruction, check whether
1070 // If the operation is with the result of a phi instruction, check whether
1083 if (Value *V = SimplifyDiv(Instruction::SDiv, Op0, Op1, Q, MaxRecurse))
1092 const Instruction *CxtI) {
1101 if (Value *V = SimplifyDiv(Instruction::UDiv, Op0, Op1, Q, MaxRecurse))
1110 const Instruction *CxtI) {
1138 const Instruction *CxtI) {
1145 static Value *SimplifyRem(Instruction::BinaryOps Opcode, Value *Op0, Value *Op1,
1183 if ((Opcode == Instruction::SRem &&
1185 (Opcode == Instruction::URem &&
1189 // If the operation is with the result of a select instruction, check whether
1195 // If the operation is with the result of a phi instruction, check whether
1208 if (Value *V = SimplifyRem(Instruction::SRem, Op0, Op1, Q, MaxRecurse))
1217 const Instruction *CxtI) {
1226 if (Value *V = SimplifyRem(Instruction::URem, Op0, Op1, Q, MaxRecurse))
1235 const Instruction *CxtI) {
1263 const Instruction *CxtI) {
1318 // If the operation is with the result of a select instruction, check whether
1324 // If the operation is with the result of a phi instruction, check whether
1368 if (Value *V = SimplifyShift(Instruction::Shl, Op0, Op1, Q, MaxRecurse))
1386 const Instruction *CxtI) {
1395 if (Value *V = SimplifyRightShift(Instruction::LShr, Op0, Op1, isExact, Q,
1411 const Instruction *CxtI) {
1420 if (Value *V = SimplifyRightShift(Instruction::AShr, Op0, Op1, isExact, Q,
1445 const Instruction *CxtI) {
1550 return ConstantFoldInstOperands(Instruction::And, CLHS->getType(),
1611 if (Value *V = SimplifyAssociativeBinOp(Instruction::And, Op0, Op1, Q,
1616 if (Value *V = ExpandBinOp(Instruction::And, Op0, Op1, Instruction::Or,
1621 if (Value *V = ExpandBinOp(Instruction::And, Op0, Op1, Instruction::Xor,
1625 // If the operation is with the result of a select instruction, check whether
1628 if (Value *V = ThreadBinOpOverSelect(Instruction::And, Op0, Op1, Q,
1632 // If the operation is with the result of a phi instruction, check whether
1635 if (Value *V = ThreadBinOpOverPHI(Instruction::And, Op0, Op1, Q,
1645 const Instruction *CxtI) {
1709 return ConstantFoldInstOperands(Instruction::Or, CLHS->getType(),
1769 if (Value *V = SimplifyAssociativeBinOp(Instruction::Or, Op0, Op1, Q,
1774 if (Value *V = ExpandBinOp(Instruction::Or, Op0, Op1, Instruction::And, Q,
1778 // If the operation is with the result of a select instruction, check whether
1781 if (Value *V = ThreadBinOpOverSelect(Instruction::Or, Op0, Op1, Q,
1821 // If the operation is with the result of a phi instruction, check whether
1824 if (Value *V = ThreadBinOpOverPHI(Instruction::Or, Op0, Op1, Q, MaxRecurse))
1833 const Instruction *CxtI) {
1845 return ConstantFoldInstOperands(Instruction::Xor, CLHS->getType(),
1871 if (Value *V = SimplifyAssociativeBinOp(Instruction::Xor, Op0, Op1, Q,
1890 const Instruction *CxtI) {
2013 // instruction kind specifically for static allocas. Such a new instruction
2361 Instruction *LI = cast<CastInst>(LHS);
2522 // Analyze the case when either LHS or RHS is an add instruction.
2526 if (LBO && LBO->getOpcode() == Instruction::Add) {
2532 if (RBO && RBO->getOpcode() == Instruction::Add) {
2747 case Instruction::UDiv:
2748 case Instruction::LShr:
2752 case Instruction::SDiv:
2753 case Instruction::AShr:
2760 case Instruction::Shl: {
3009 // If the comparison is with the result of a select instruction, check whether
3015 // If the comparison is with the result of a phi instruction, check whether
3028 Instruction *CxtI) {
3125 // If the comparison is with the result of a select instruction, check whether
3131 // If the comparison is with the result of a phi instruction, check whether
3144 const Instruction *CxtI) {
3239 const Instruction *CxtI) {
3256 // Compute the (pointer) type returned by the GEP instruction.
3331 const Instruction *CxtI) {
3369 const Instruction *CxtI) {
3400 // instruction, we cannot return X as the result of the PHI node unless it
3410 return ConstantFoldInstOperands(Instruction::Trunc, Ty, C, Q.DL, Q.TLI);
3418 const Instruction *CxtI) {
3430 case Instruction::Add:
3433 case Instruction::FAdd:
3436 case Instruction::Sub:
3439 case Instruction::FSub:
3442 case Instruction::Mul: return SimplifyMulInst (LHS, RHS, Q, MaxRecurse);
3443 case Instruction::FMul:
3445 case Instruction::SDiv: return SimplifySDivInst(LHS, RHS, Q, MaxRecurse);
3446 case Instruction::UDiv: return SimplifyUDivInst(LHS, RHS, Q, MaxRecurse);
3447 case Instruction::FDiv:
3449 case Instruction::SRem: return SimplifySRemInst(LHS, RHS, Q, MaxRecurse);
3450 case Instruction::URem: return SimplifyURemInst(LHS, RHS, Q, MaxRecurse);
3451 case Instruction::FRem:
3453 case Instruction::Shl:
3456 case Instruction::LShr:
3458 case Instruction::AShr:
3460 case Instruction::And: return SimplifyAndInst(LHS, RHS, Q, MaxRecurse);
3461 case Instruction::Or: return SimplifyOrInst (LHS, RHS, Q, MaxRecurse);
3462 case Instruction::Xor: return SimplifyXorInst(LHS, RHS, Q, MaxRecurse);
3472 if (Instruction::isAssociative(Opcode))
3476 // If the operation is with the result of a select instruction check whether
3482 // If the operation is with the result of a phi instruction, check whether
3500 case Instruction::FAdd:
3502 case Instruction::FSub:
3504 case Instruction::FMul:
3514 const Instruction *CxtI) {
3523 const Instruction *CxtI) {
3540 const Instruction *CxtI) {
3616 AssumptionCache *AC, const Instruction *CxtI) {
3624 const Instruction *CxtI) {
3630 /// instruction. If not, this returns null.
3631 Value *llvm::SimplifyInstruction(Instruction *I, const DataLayout &DL,
3640 case Instruction::FAdd:
3644 case Instruction::Add:
3650 case Instruction::FSub:
3654 case Instruction::Sub:
3660 case Instruction::FMul:
3664 case Instruction::Mul:
3668 case Instruction::SDiv:
3672 case Instruction::UDiv:
3676 case Instruction::FDiv:
3680 case Instruction::SRem:
3684 case Instruction::URem:
3688 case Instruction::FRem:
3692 case Instruction::Shl:
3698 case Instruction::LShr:
3703 case Instruction::AShr:
3708 case Instruction::And:
3712 case Instruction::Or:
3716 case Instruction::Xor:
3720 case Instruction::ICmp:
3725 case Instruction::FCmp:
3730 case Instruction::Select:
3734 case Instruction::GetElementPtr: {
3739 case Instruction::InsertValue: {
3746 case Instruction::PHI:
3749 case Instruction::Call: {
3755 case Instruction::Trunc:
3762 /// instruction simplified to itself. Make life easier for users by
3772 /// replace the instruction 'I'. Otherwise, we simply add 'I' to the list of
3778 static bool replaceAndRecursivelySimplifyImpl(Instruction *I, Value *SimpleV,
3783 SmallSetVector<Instruction *, 8> Worklist;
3791 Worklist.insert(cast<Instruction>(U));
3793 // Replace the instruction with its simplified value.
3796 // Gracefully handle edge cases where the instruction is not wired into any
3808 // See if this instruction simplifies.
3815 // Stash away all the uses of the old instruction so we can check them for
3819 Worklist.insert(cast<Instruction>(U));
3821 // Replace the instruction with its simplified value.
3824 // Gracefully handle edge cases where the instruction is not wired into any
3832 bool llvm::recursivelySimplifyInstruction(Instruction *I,
3839 bool llvm::replaceAndRecursivelySimplify(Instruction *I, Value *SimpleV,