// Canonicalize a shift amount constant operand to modulo the bit-width.
Constant *WidthC = ConstantInt::get(Ty, BitWidth);
Constant *ModuloC = ConstantExpr::getURem(ShAmtC, WidthC);
- if (ModuloC != ShAmtC) {
- II->setArgOperand(2, ModuloC);
- return II;
- }
+ if (ModuloC != ShAmtC)
+ return replaceOperand(*II, 2, ModuloC);
+
assert(ConstantExpr::getICmp(ICmpInst::ICMP_UGT, WidthC, ShAmtC) ==
ConstantInt::getTrue(CmpInst::makeCmpResultType(Ty)) &&
"Shift amount expected to be modulo bitwidth");
Value *Src1 = II->getArgOperand(1);
Value *X, *Y;
if (match(Src0, m_FNeg(m_Value(X))) && match(Src1, m_FNeg(m_Value(Y)))) {
- II->setArgOperand(0, X);
- II->setArgOperand(1, Y);
+ replaceOperand(*II, 0, X);
+ replaceOperand(*II, 1, Y);
return II;
}
// fma fabs(x), fabs(x), z -> fma x, x, z
if (match(Src0, m_FAbs(m_Value(X))) &&
match(Src1, m_FAbs(m_Specific(X)))) {
- II->setArgOperand(0, X);
- II->setArgOperand(1, X);
+ replaceOperand(*II, 0, X);
+ replaceOperand(*II, 1, X);
return II;
}
// copysign X, (copysign ?, SignArg) --> copysign X, SignArg
Value *SignArg;
if (match(II->getArgOperand(1),
- m_Intrinsic<Intrinsic::copysign>(m_Value(), m_Value(SignArg)))) {
- II->setArgOperand(1, SignArg);
- return II;
- }
+ m_Intrinsic<Intrinsic::copysign>(m_Value(), m_Value(SignArg))))
+ return replaceOperand(*II, 1, SignArg);
break;
}
if (match(Src, m_FNeg(m_Value(X))) || match(Src, m_FAbs(m_Value(X)))) {
// cos(-x) -> cos(x)
// cos(fabs(x)) -> cos(x)
- II->setArgOperand(0, X);
- return II;
+ return replaceOperand(*II, 0, X);
}
break;
}
cast<Instruction>(Arg0)->getFastMathFlags().noInfs())) {
if (Arg0IsZero)
std::swap(A, B);
- II->setArgOperand(0, A);
- II->setArgOperand(1, B);
+ replaceOperand(*II, 0, A);
+ replaceOperand(*II, 1, B);
return II;
}
break;
getKnownAlignment(II->getArgOperand(0), DL, II, &AC, &DT);
unsigned AlignArg = II->getNumArgOperands() - 1;
ConstantInt *IntrAlign = dyn_cast<ConstantInt>(II->getArgOperand(AlignArg));
- if (IntrAlign && IntrAlign->getZExtValue() < MemAlign) {
- II->setArgOperand(AlignArg,
- ConstantInt::get(Type::getInt32Ty(II->getContext()),
- MemAlign, false));
- return II;
- }
+ if (IntrAlign && IntrAlign->getZExtValue() < MemAlign)
+ return replaceOperand(*II, AlignArg,
+ ConstantInt::get(Type::getInt32Ty(II->getContext()),
+ MemAlign, false));
break;
}
Value *Data, *Key;
if (match(KeyArg, m_ZeroInt()) &&
match(DataArg, m_Xor(m_Value(Data), m_Value(Key)))) {
- II->setArgOperand(0, Data);
- II->setArgOperand(1, Key);
+ replaceOperand(*II, 0, Data);
+ replaceOperand(*II, 1, Key);
return II;
}
break;
}
// fp_class (nnan x), qnan|snan|other -> fp_class (nnan x), other
- if (((Mask & S_NAN) || (Mask & Q_NAN)) && isKnownNeverNaN(Src0, &TLI)) {
- II->setArgOperand(1, ConstantInt::get(Src1->getType(),
- Mask & ~(S_NAN | Q_NAN)));
- return II;
- }
+ if (((Mask & S_NAN) || (Mask & Q_NAN)) && isKnownNeverNaN(Src0, &TLI))
+ return replaceOperand(*II, 1, ConstantInt::get(Src1->getType(),
+ Mask & ~(S_NAN | Q_NAN)));
const ConstantFP *CVal = dyn_cast<ConstantFP>(Src0);
if (!CVal) {
if ((Width & (IntSize - 1)) == 0)
return replaceInstUsesWith(*II, ConstantInt::getNullValue(Ty));
- if (Width >= IntSize) {
- // Hardware ignores high bits, so remove those.
- II->setArgOperand(2, ConstantInt::get(CWidth->getType(),
- Width & (IntSize - 1)));
- return II;
- }
+ // Hardware ignores high bits, so remove those.
+ if (Width >= IntSize)
+ return replaceOperand(*II, 2, ConstantInt::get(CWidth->getType(),
+ Width & (IntSize - 1)));
}
unsigned Offset;
ConstantInt *COffset = dyn_cast<ConstantInt>(II->getArgOperand(1));
if (COffset) {
Offset = COffset->getZExtValue();
- if (Offset >= IntSize) {
- II->setArgOperand(1, ConstantInt::get(COffset->getType(),
- Offset & (IntSize - 1)));
- return II;
- }
+ if (Offset >= IntSize)
+ return replaceOperand(*II, 1, ConstantInt::get(COffset->getType(),
+ Offset & (IntSize - 1)));
}
bool Signed = IID == Intrinsic::amdgcn_sbfe;
(IsCompr && ((EnBits & (0x3 << (2 * I))) == 0))) {
Value *Src = II->getArgOperand(I + 2);
if (!isa<UndefValue>(Src)) {
- II->setArgOperand(I + 2, UndefValue::get(Src->getType()));
+ replaceOperand(*II, I + 2, UndefValue::get(Src->getType()));
Changed = true;
}
}
((match(Src1, m_One()) && match(Src0, m_ZExt(m_Value(ExtSrc)))) ||
(match(Src1, m_AllOnes()) && match(Src0, m_SExt(m_Value(ExtSrc))))) &&
ExtSrc->getType()->isIntegerTy(1)) {
- II->setArgOperand(1, ConstantInt::getNullValue(Src1->getType()));
- II->setArgOperand(2, ConstantInt::get(CC->getType(), CmpInst::ICMP_NE));
+ replaceOperand(*II, 1, ConstantInt::getNullValue(Src1->getType()));
+ replaceOperand(*II, 2, ConstantInt::get(CC->getType(), CmpInst::ICMP_NE));
return II;
}
MoveI = MoveI->getNextNonDebugInstruction();
Temp->moveBefore(II);
}
- II->setArgOperand(0, Builder.CreateAnd(CurrCond, NextCond));
+ replaceOperand(*II, 0, Builder.CreateAnd(CurrCond, NextCond));
}
eraseInstFromFunction(*NextInst);
return II;
// Does "B op C" simplify?
if (Value *V = SimplifyBinOp(Opcode, B, C, SQ.getWithInstruction(&I))) {
// It simplifies to V. Form "A op V".
- I.setOperand(0, A);
- I.setOperand(1, V);
+ replaceOperand(I, 0, A);
+ replaceOperand(I, 1, V);
bool IsNUW = hasNoUnsignedWrap(I) && hasNoUnsignedWrap(*Op0);
bool IsNSW = maintainNoSignedWrap(I, B, C) && hasNoSignedWrap(*Op0);
// Does "A op B" simplify?
if (Value *V = SimplifyBinOp(Opcode, A, B, SQ.getWithInstruction(&I))) {
// It simplifies to V. Form "V op C".
- I.setOperand(0, V);
- I.setOperand(1, C);
+ replaceOperand(I, 0, V);
+ replaceOperand(I, 1, C);
// Conservatively clear the optional flags, since they may not be
// preserved by the reassociation.
ClearSubclassDataAfterReassociation(I);
// Does "C op A" simplify?
if (Value *V = SimplifyBinOp(Opcode, C, A, SQ.getWithInstruction(&I))) {
// It simplifies to V. Form "V op B".
- I.setOperand(0, V);
- I.setOperand(1, B);
+ replaceOperand(I, 0, V);
+ replaceOperand(I, 1, B);
// Conservatively clear the optional flags, since they may not be
// preserved by the reassociation.
ClearSubclassDataAfterReassociation(I);
// Does "C op A" simplify?
if (Value *V = SimplifyBinOp(Opcode, C, A, SQ.getWithInstruction(&I))) {
// It simplifies to V. Form "B op V".
- I.setOperand(0, B);
- I.setOperand(1, V);
+ replaceOperand(I, 0, B);
+ replaceOperand(I, 1, V);
// Conservatively clear the optional flags, since they may not be
// preserved by the reassociation.
ClearSubclassDataAfterReassociation(I);
}
InsertNewInstWith(NewBO, I);
NewBO->takeName(Op1);
- I.setOperand(0, NewBO);
- I.setOperand(1, ConstantExpr::get(Opcode, C1, C2));
+ replaceOperand(I, 0, NewBO);
+ replaceOperand(I, 1, ConstantExpr::get(Opcode, C1, C2));
// Conservatively clear the optional flags, since they may not be
// preserved by the reassociation.
ClearSubclassDataAfterReassociation(I);
if (match(&BI, m_Br(m_Not(m_Value(X)), m_BasicBlock(), m_BasicBlock())) &&
!isa<Constant>(X)) {
// Swap Destinations and condition...
- BI.setCondition(X);
BI.swapSuccessors();
- return &BI;
+ return replaceOperand(BI, 0, X);
}
// If the condition is irrelevant, remove the use so that other
// transforms on the condition become more effective.
if (BI.isConditional() && !isa<ConstantInt>(BI.getCondition()) &&
- BI.getSuccessor(0) == BI.getSuccessor(1)) {
- BI.setCondition(ConstantInt::getFalse(BI.getCondition()->getType()));
- return &BI;
- }
+ BI.getSuccessor(0) == BI.getSuccessor(1))
+ return replaceOperand(
+ BI, 0, ConstantInt::getFalse(BI.getCondition()->getType()));
// Canonicalize, for example, icmp_ne -> icmp_eq or fcmp_one -> fcmp_oeq.
CmpInst::Predicate Pred;
"Result of expression should be constant");
Case.setValue(cast<ConstantInt>(NewCase));
}
- SI.setCondition(Op0);
- return &SI;
+ return replaceOperand(SI, 0, Op0);
}
KnownBits Known = computeKnownBits(Cond, 0, &SI);
IntegerType *Ty = IntegerType::get(SI.getContext(), NewWidth);
Builder.SetInsertPoint(&SI);
Value *NewCond = Builder.CreateTrunc(Cond, Ty, "trunc");
- SI.setCondition(NewCond);
for (auto Case : SI.cases()) {
APInt TruncatedCase = Case.getCaseValue()->getValue().trunc(NewWidth);
Case.setValue(ConstantInt::get(SI.getContext(), TruncatedCase));
}
- return &SI;
+ return replaceOperand(SI, 0, NewCond);
}
return nullptr;