Lines Matching full:instruction
64 static void PrintOps(Instruction *I, const SmallVectorImpl<ValueEntry> &Ops) {
66 dbgs() << Instruction::getOpcodeName(I->getOpcode()) << " "
163 SetVector<AssertingVH<Instruction> > RedoInsts;
179 void canonicalizeOperands(Instruction *I);
184 Value *OptimizeAdd(Instruction *I, SmallVectorImpl<ValueEntry> &Ops);
185 Value *OptimizeXor(Instruction *I, SmallVectorImpl<ValueEntry> &Ops);
186 bool CombineXorOpnd(Instruction *I, XorOpnd *Opnd1, APInt &ConstOpnd,
188 bool CombineXorOpnd(Instruction *I, XorOpnd *Opnd1, XorOpnd *Opnd2,
196 void EraseInst(Instruction *I);
197 void OptimizeInst(Instruction *I);
198 Instruction *canonicalizeNegConstExpr(Instruction *I);
205 Instruction *I = dyn_cast<Instruction>(V);
208 if (I && (I->getOpcode() == Instruction::Or ||
209 I->getOpcode() == Instruction::And)) {
218 isOr = (I->getOpcode() == Instruction::Or);
236 /// isReassociableOp - Return true if V is an instruction of the specified
239 if (V->hasOneUse() && isa<Instruction>(V) &&
240 cast<Instruction>(V)->getOpcode() == Opcode &&
242 cast<Instruction>(V)->hasUnsafeAlgebra()))
249 if (V->hasOneUse() && isa<Instruction>(V) &&
250 (cast<Instruction>(V)->getOpcode() == Opcode1 ||
251 cast<Instruction>(V)->getOpcode() == Opcode2) &&
253 cast<Instruction>(V)->hasUnsafeAlgebra()))
258 static bool isUnmovableInstruction(Instruction *I) {
260 case Instruction::PHI:
261 case Instruction::LandingPad:
262 case Instruction::Alloca:
263 case Instruction::Load:
264 case Instruction::Invoke:
265 case Instruction::UDiv:
266 case Instruction::SDiv:
267 case Instruction::FDiv:
268 case Instruction::URem:
269 case Instruction::SRem:
270 case Instruction::FRem:
272 case Instruction::Call:
304 Instruction *I = dyn_cast<Instruction>(V);
322 // If this is a not or neg instruction, do not count it for rank. This
334 void Reassociate::canonicalizeOperands(Instruction *I) {
351 Instruction *InsertBefore, Value *FlagsOp) {
363 Instruction *InsertBefore, Value *FlagsOp) {
375 Instruction *InsertBefore, Value *FlagsOp) {
387 static BinaryOperator *LowerNegateToMultiply(Instruction *Neg) {
436 if (Instruction::isIdempotent(Opcode)) {
443 if (Instruction::isNilpotent(Opcode)) {
449 if (Opcode == Instruction::Add || Opcode == Instruction::FAdd) {
455 assert((Opcode == Instruction::Mul || Opcode == Instruction::FMul) &&
534 /// The expression is maximal: if some instruction is a binary operator of the
536 /// then the instruction also belongs to the expression, is not a leaf node of
593 // X has any other uses, for example in a return instruction, then we consider
684 assert((!isa<Instruction>(Op) ||
685 cast<Instruction>(Op)->getOpcode() != Opcode
687 !cast<Instruction>(Op)->hasUnsafeAlgebra())) &&
694 if ((Opcode == Instruction::Mul && BinaryOperator::isNeg(BO)) ||
695 (Opcode == Instruction::FMul && BinaryOperator::isFNeg(BO))) {
871 NewOp = BinaryOperator::Create(Instruction::BinaryOps(Opcode),
913 /// NegateValue - Insert instructions before the instruction pointed to by BI,
915 /// version of the value is returned, and BI is left pointing at the instruction
917 static Value *NegateValue(Value *V, Instruction *BI) {
936 isReassociableOp(V, Instruction::Add, Instruction::FAdd)) {
941 // We must move the add instruction here, because the neg instructions do
942 // not dominate the old add instruction in general. By moving it, we are
944 // instruction we are about to insert after them.
951 // Okay, we need to materialize a negated version of V with an instruction.
959 // non-instruction value) or right after the definition. These negates will
968 if (Instruction *InstInput = dyn_cast<Instruction>(V)) {
983 // Insert a 'neg' instruction that subtracts the value from zero to get the
990 static bool ShouldBreakUpSubtract(Instruction *Sub) {
1002 if (isReassociableOp(V0, Instruction::Add, Instruction::FAdd) ||
1003 isReassociableOp(V0, Instruction::Sub, Instruction::FSub))
1006 if (isReassociableOp(V1, Instruction::Add, Instruction::FAdd) ||
1007 isReassociableOp(V1, Instruction::Sub, Instruction::FSub))
1011 (isReassociableOp(VB, Instruction::Add, Instruction::FAdd) ||
1012 isReassociableOp(VB, Instruction::Sub, Instruction::FSub)))
1021 static BinaryOperator *BreakUpSubtract(Instruction *Sub) {
1022 // Convert a subtract into an add and a neg instruction. This allows sub
1025 // Calculate the negative value of Operand 1 of the sub instruction,
1026 // and set it as the RHS of the add instruction we just made.
1034 // Everyone now refers to the add instruction.
1045 static BinaryOperator *ConvertShiftToMul(Instruction *Shl) {
1054 // Everyone now refers to the mul instruction.
1080 if (Instruction *I1 = dyn_cast<Instruction>(Ops[j].Op))
1081 if (Instruction *I2 = dyn_cast<Instruction>(X))
1089 if (Instruction *I1 = dyn_cast<Instruction>(Ops[j].Op))
1090 if (Instruction *I2 = dyn_cast<Instruction>(X))
1099 static Value *EmitAddTreeOfValues(Instruction *I,
1113 BinaryOperator *BO = isReassociableOp(V, Instruction::Mul, Instruction::FMul);
1189 BinaryOperator *BO = isReassociableOp(V, Instruction::Mul, Instruction::FMul);
1201 /// instruction. This optimizes based on identities. If it can be reduced to
1215 if (Opcode == Instruction::And) // ...&X&~X = 0
1218 if (Opcode == Instruction::Or) // ...|X|~X = -1
1227 if (Opcode == Instruction::And || Opcode == Instruction::Or) {
1236 assert(Opcode == Instruction::Xor);
1250 /// instruction with the given two operands, and return the resulting
1251 /// instruction. There are two special cases: 1) if the constant operand is 0,
1254 static Value *createAndInstr(Instruction *InsertBefore, Value *Opnd,
1259 Instruction *I;
1277 bool Reassociate::CombineXorOpnd(Instruction *I, XorOpnd *Opnd1,
1296 if (Instruction *T = dyn_cast<Instruction>(Opnd1->getValue()))
1312 bool Reassociate::CombineXorOpnd(Instruction *I, XorOpnd *Opnd1, XorOpnd *Opnd2,
1318 // This many instruction become dead.(At least "Opnd1 ^ Opnd2" will die.)
1376 if (Instruction *T = dyn_cast<Instruction>(Opnd1->getValue()))
1378 if (Instruction *T = dyn_cast<Instruction>(Opnd2->getValue()))
1384 /// Optimize a series of operands to an 'xor' instruction. If it can be reduced
1387 Value *Reassociate::OptimizeXor(Instruction *I,
1389 if (Value *V = OptimizeAndOrXor(Instruction::Xor, Ops))
1493 /// OptimizeAdd - Optimize a series of operands to an 'add' instruction. This
1496 Value *Reassociate::OptimizeAdd(Instruction *I,
1523 Instruction *Mul = CreateMul(TheOp, C, "factor", I, I);
1599 isReassociableOp(Ops[i].Op, Instruction::Mul, Instruction::FMul);
1657 // Create a new instruction that uses the MaxOccVal twice. If we don't do
1661 Instruction *DummyInst =
1670 isReassociableOp(Ops[i].Op, Instruction::Mul, Instruction::FMul);
1699 if (Instruction *VI = dyn_cast<Instruction>(V))
1703 Instruction *V2 = CreateMul(V, MaxOccVal, "tmp", I, I);
1832 if (Instruction *MI = dyn_cast<Instruction>(M))
1917 case Instruction::And:
1918 case Instruction::Or:
1923 case Instruction::Xor:
1928 case Instruction::Add:
1929 case Instruction::FAdd:
1934 case Instruction::Mul:
1935 case Instruction::FMul:
1946 /// EraseInst - Zap the given instruction, adding interesting operands to the
1948 void Reassociate::EraseInst(Instruction *I) {
1951 // Erase the dead instruction.
1956 SmallPtrSet<Instruction *, 8> Visited; // Detect self-referential nodes.
1958 if (Instruction *Op = dyn_cast<Instruction>(Ops[i])) {
1972 Instruction *Reassociate::canonicalizeNegConstExpr(Instruction *I) {
1976 // Must be a mul, fmul, or fdiv instruction.
1978 if (Opcode != Instruction::Mul && Opcode != Instruction::FMul &&
1979 Opcode != Instruction::FDiv)
2001 Instruction *User = I->user_back();
2006 if (UserOpcode != Instruction::Add && UserOpcode != Instruction::FAdd &&
2007 UserOpcode != Instruction::Sub && UserOpcode != Instruction::FSub)
2036 case Instruction::Add:
2039 case Instruction::Sub:
2042 case Instruction::FAdd:
2046 case Instruction::FSub:
2061 /// OptimizeInst - Inspect and optimize the given instruction. Note that erasing
2063 void Reassociate::OptimizeInst(Instruction *I) {
2068 if (I->getOpcode() == Instruction::Shl && isa<ConstantInt>(I->getOperand(1)))
2071 if (isReassociableOp(I->getOperand(0), Instruction::Mul) ||
2073 (isReassociableOp(I->user_back(), Instruction::Mul) ||
2074 isReassociableOp(I->user_back(), Instruction::Add)))) {
2075 Instruction *NI = ConvertShiftToMul(I);
2082 if (Instruction *Res = canonicalizeNegConstExpr(I))
2093 if (I->getType()->isVectorTy() && I->getOpcode() == Instruction::Xor)
2109 // If this is a subtract instruction which is not already in negate form,
2111 if (I->getOpcode() == Instruction::Sub) {
2113 Instruction *NI = BreakUpSubtract(I);
2120 if (isReassociableOp(I->getOperand(1), Instruction::Mul) &&
2122 !isReassociableOp(I->user_back(), Instruction::Mul))) {
2123 Instruction *NI = LowerNegateToMultiply(I);
2129 } else if (I->getOpcode() == Instruction::FSub) {
2131 Instruction *NI = BreakUpSubtract(I);
2138 if (isReassociableOp(I->getOperand(1), Instruction::FMul) &&
2140 !isReassociableOp(I->user_back(), Instruction::FMul))) {
2141 Instruction *NI = LowerNegateToMultiply(I);
2149 // If this instruction is an associative binary operator, process it.
2159 // If this is an add tree that is used by a sub instruction, ignore it
2161 if (BO->hasOneUse() && BO->getOpcode() == Instruction::Add &&
2162 cast<Instruction>(BO->user_back())->getOpcode() == Instruction::Sub)
2164 if (BO->hasOneUse() && BO->getOpcode() == Instruction::FAdd &&
2165 cast<Instruction>(BO->user_back())->getOpcode() == Instruction::FSub)
2204 if (Instruction *VI = dyn_cast<Instruction>(V))
2216 if (I->getOpcode() == Instruction::Mul &&
2217 cast<Instruction>(I->user_back())->getOpcode() == Instruction::Add &&
2222 } else if (I->getOpcode() == Instruction::FMul &&
2223 cast<Instruction>(I->user_back())->getOpcode() ==
2224 Instruction::FAdd &&
2242 if (Instruction *OI = dyn_cast<Instruction>(Ops[0].Op))
2262 // Optimize every instruction in the basic block.
2274 Instruction *I = RedoInsts.pop_back_val();