1 //===- InstCombineMulDivRem.cpp -------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the visit functions for mul, fmul, sdiv, udiv, fdiv,
13 //===----------------------------------------------------------------------===//
15 #include "InstCombine.h"
16 #include "llvm/IntrinsicInst.h"
17 #include "llvm/Analysis/InstructionSimplify.h"
18 #include "llvm/Support/PatternMatch.h"
20 using namespace PatternMatch;
22 /// MultiplyOverflows - True if the multiply can not be expressed in an int
24 static bool MultiplyOverflows(ConstantInt *C1, ConstantInt *C2, bool sign) {
25 uint32_t W = C1->getBitWidth();
26 APInt LHSExt = C1->getValue(), RHSExt = C2->getValue();
28 LHSExt = LHSExt.sext(W * 2);
29 RHSExt = RHSExt.sext(W * 2);
31 LHSExt = LHSExt.zext(W * 2);
32 RHSExt = RHSExt.zext(W * 2);
35 APInt MulExt = LHSExt * RHSExt;
38 return MulExt.ugt(APInt::getLowBitsSet(W * 2, W));
40 APInt Min = APInt::getSignedMinValue(W).sext(W * 2);
41 APInt Max = APInt::getSignedMaxValue(W).sext(W * 2);
42 return MulExt.slt(Min) || MulExt.sgt(Max);
45 Instruction *InstCombiner::visitMul(BinaryOperator &I) {
46 bool Changed = SimplifyAssociativeOrCommutative(I);
47 Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
49 if (Value *V = SimplifyMulInst(Op0, Op1, TD))
50 return ReplaceInstUsesWith(I, V);
52 if (Value *V = SimplifyUsingDistributiveLaws(I))
53 return ReplaceInstUsesWith(I, V);
55 if (match(Op1, m_AllOnes())) // X * -1 == 0 - X
56 return BinaryOperator::CreateNeg(Op0, I.getName());
58 if (ConstantInt *CI = dyn_cast<ConstantInt>(Op1)) {
60 // ((X << C1)*C2) == (X * (C2 << C1))
61 if (BinaryOperator *SI = dyn_cast<BinaryOperator>(Op0))
62 if (SI->getOpcode() == Instruction::Shl)
63 if (Constant *ShOp = dyn_cast<Constant>(SI->getOperand(1)))
64 return BinaryOperator::CreateMul(SI->getOperand(0),
65 ConstantExpr::getShl(CI, ShOp));
67 const APInt &Val = CI->getValue();
68 if (Val.isPowerOf2()) { // Replace X*(2^C) with X << C
69 Constant *NewCst = ConstantInt::get(Op0->getType(), Val.logBase2());
70 BinaryOperator *Shl = BinaryOperator::CreateShl(Op0, NewCst);
71 if (I.hasNoSignedWrap()) Shl->setHasNoSignedWrap();
72 if (I.hasNoUnsignedWrap()) Shl->setHasNoUnsignedWrap();
76 // Canonicalize (X+C1)*CI -> X*CI+C1*CI.
77 { Value *X; ConstantInt *C1;
78 if (Op0->hasOneUse() &&
79 match(Op0, m_Add(m_Value(X), m_ConstantInt(C1)))) {
80 Value *Add = Builder->CreateMul(X, CI, "tmp");
81 return BinaryOperator::CreateAdd(Add, Builder->CreateMul(C1, CI));
86 // Simplify mul instructions with a constant RHS.
87 if (isa<Constant>(Op1)) {
88 // Try to fold constant mul into select arguments.
89 if (SelectInst *SI = dyn_cast<SelectInst>(Op0))
90 if (Instruction *R = FoldOpIntoSelect(I, SI))
93 if (isa<PHINode>(Op0))
94 if (Instruction *NV = FoldOpIntoPhi(I))
98 if (Value *Op0v = dyn_castNegVal(Op0)) // -X * -Y = X*Y
99 if (Value *Op1v = dyn_castNegVal(Op1))
100 return BinaryOperator::CreateMul(Op0v, Op1v);
102 // (X / Y) * Y = X - (X % Y)
103 // (X / Y) * -Y = (X % Y) - X
106 BinaryOperator *BO = dyn_cast<BinaryOperator>(Op0);
108 (BO->getOpcode() != Instruction::UDiv &&
109 BO->getOpcode() != Instruction::SDiv)) {
111 BO = dyn_cast<BinaryOperator>(Op1);
113 Value *Neg = dyn_castNegVal(Op1C);
114 if (BO && BO->hasOneUse() &&
115 (BO->getOperand(1) == Op1C || BO->getOperand(1) == Neg) &&
116 (BO->getOpcode() == Instruction::UDiv ||
117 BO->getOpcode() == Instruction::SDiv)) {
118 Value *Op0BO = BO->getOperand(0), *Op1BO = BO->getOperand(1);
120 // If the division is exact, X % Y is zero, so we end up with X or -X.
121 if (PossiblyExactOperator *SDiv = dyn_cast<PossiblyExactOperator>(BO))
122 if (SDiv->isExact()) {
124 return ReplaceInstUsesWith(I, Op0BO);
125 return BinaryOperator::CreateNeg(Op0BO);
129 if (BO->getOpcode() == Instruction::UDiv)
130 Rem = Builder->CreateURem(Op0BO, Op1BO);
132 Rem = Builder->CreateSRem(Op0BO, Op1BO);
136 return BinaryOperator::CreateSub(Op0BO, Rem);
137 return BinaryOperator::CreateSub(Rem, Op0BO);
141 /// i1 mul -> i1 and.
142 if (I.getType()->isIntegerTy(1))
143 return BinaryOperator::CreateAnd(Op0, Op1);
145 // X*(1 << Y) --> X << Y
146 // (1 << Y)*X --> X << Y
149 if (match(Op0, m_Shl(m_One(), m_Value(Y))))
150 return BinaryOperator::CreateShl(Op1, Y);
151 if (match(Op1, m_Shl(m_One(), m_Value(Y))))
152 return BinaryOperator::CreateShl(Op0, Y);
155 // If one of the operands of the multiply is a cast from a boolean value, then
156 // we know the bool is either zero or one, so this is a 'masking' multiply.
157 // X * Y (where Y is 0 or 1) -> X & (0-Y)
158 if (!I.getType()->isVectorTy()) {
159 // -2 is "-1 << 1" so it is all bits set except the low one.
160 APInt Negative2(I.getType()->getPrimitiveSizeInBits(), (uint64_t)-2, true);
162 Value *BoolCast = 0, *OtherOp = 0;
163 if (MaskedValueIsZero(Op0, Negative2))
164 BoolCast = Op0, OtherOp = Op1;
165 else if (MaskedValueIsZero(Op1, Negative2))
166 BoolCast = Op1, OtherOp = Op0;
169 Value *V = Builder->CreateSub(Constant::getNullValue(I.getType()),
171 return BinaryOperator::CreateAnd(V, OtherOp);
175 return Changed ? &I : 0;
178 Instruction *InstCombiner::visitFMul(BinaryOperator &I) {
179 bool Changed = SimplifyAssociativeOrCommutative(I);
180 Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
182 // Simplify mul instructions with a constant RHS...
183 if (Constant *Op1C = dyn_cast<Constant>(Op1)) {
184 if (ConstantFP *Op1F = dyn_cast<ConstantFP>(Op1C)) {
185 // "In IEEE floating point, x*1 is not equivalent to x for nans. However,
186 // ANSI says we can drop signals, so we can do this anyway." (from GCC)
187 if (Op1F->isExactlyValue(1.0))
188 return ReplaceInstUsesWith(I, Op0); // Eliminate 'fmul double %X, 1.0'
189 } else if (Op1C->getType()->isVectorTy()) {
190 if (ConstantVector *Op1V = dyn_cast<ConstantVector>(Op1C)) {
191 // As above, vector X*splat(1.0) -> X in all defined cases.
192 if (Constant *Splat = Op1V->getSplatValue()) {
193 if (ConstantFP *F = dyn_cast<ConstantFP>(Splat))
194 if (F->isExactlyValue(1.0))
195 return ReplaceInstUsesWith(I, Op0);
200 // Try to fold constant mul into select arguments.
201 if (SelectInst *SI = dyn_cast<SelectInst>(Op0))
202 if (Instruction *R = FoldOpIntoSelect(I, SI))
205 if (isa<PHINode>(Op0))
206 if (Instruction *NV = FoldOpIntoPhi(I))
210 if (Value *Op0v = dyn_castFNegVal(Op0)) // -X * -Y = X*Y
211 if (Value *Op1v = dyn_castFNegVal(Op1))
212 return BinaryOperator::CreateFMul(Op0v, Op1v);
214 return Changed ? &I : 0;
217 /// SimplifyDivRemOfSelect - Try to fold a divide or remainder of a select
219 bool InstCombiner::SimplifyDivRemOfSelect(BinaryOperator &I) {
220 SelectInst *SI = cast<SelectInst>(I.getOperand(1));
222 // div/rem X, (Cond ? 0 : Y) -> div/rem X, Y
223 int NonNullOperand = -1;
224 if (Constant *ST = dyn_cast<Constant>(SI->getOperand(1)))
225 if (ST->isNullValue())
227 // div/rem X, (Cond ? Y : 0) -> div/rem X, Y
228 if (Constant *ST = dyn_cast<Constant>(SI->getOperand(2)))
229 if (ST->isNullValue())
232 if (NonNullOperand == -1)
235 Value *SelectCond = SI->getOperand(0);
237 // Change the div/rem to use 'Y' instead of the select.
238 I.setOperand(1, SI->getOperand(NonNullOperand));
240 // Okay, we know we replace the operand of the div/rem with 'Y' with no
241 // problem. However, the select, or the condition of the select may have
242 // multiple uses. Based on our knowledge that the operand must be non-zero,
243 // propagate the known value for the select into other uses of it, and
244 // propagate a known value of the condition into its other users.
246 // If the select and condition only have a single use, don't bother with this,
248 if (SI->use_empty() && SelectCond->hasOneUse())
251 // Scan the current block backward, looking for other uses of SI.
252 BasicBlock::iterator BBI = &I, BBFront = I.getParent()->begin();
254 while (BBI != BBFront) {
256 // If we found a call to a function, we can't assume it will return, so
257 // information from below it cannot be propagated above it.
258 if (isa<CallInst>(BBI) && !isa<IntrinsicInst>(BBI))
261 // Replace uses of the select or its condition with the known values.
262 for (Instruction::op_iterator I = BBI->op_begin(), E = BBI->op_end();
265 *I = SI->getOperand(NonNullOperand);
267 } else if (*I == SelectCond) {
268 *I = NonNullOperand == 1 ? ConstantInt::getTrue(BBI->getContext()) :
269 ConstantInt::getFalse(BBI->getContext());
274 // If we past the instruction, quit looking for it.
277 if (&*BBI == SelectCond)
280 // If we ran out of things to eliminate, break out of the loop.
281 if (SelectCond == 0 && SI == 0)
289 /// This function implements the transforms common to both integer division
290 /// instructions (udiv and sdiv). It is called by the visitors to those integer
291 /// division instructions.
292 /// @brief Common integer divide transforms
293 Instruction *InstCombiner::commonIDivTransforms(BinaryOperator &I) {
294 Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
296 // Handle cases involving: [su]div X, (select Cond, Y, Z)
297 // This does not apply for fdiv.
298 if (isa<SelectInst>(Op1) && SimplifyDivRemOfSelect(I))
301 if (ConstantInt *RHS = dyn_cast<ConstantInt>(Op1)) {
302 // (X / C1) / C2 -> X / (C1*C2)
303 if (Instruction *LHS = dyn_cast<Instruction>(Op0))
304 if (Instruction::BinaryOps(LHS->getOpcode()) == I.getOpcode())
305 if (ConstantInt *LHSRHS = dyn_cast<ConstantInt>(LHS->getOperand(1))) {
306 if (MultiplyOverflows(RHS, LHSRHS,
307 I.getOpcode()==Instruction::SDiv))
308 return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
309 return BinaryOperator::Create(I.getOpcode(), LHS->getOperand(0),
310 ConstantExpr::getMul(RHS, LHSRHS));
313 if (!RHS->isZero()) { // avoid X udiv 0
314 if (SelectInst *SI = dyn_cast<SelectInst>(Op0))
315 if (Instruction *R = FoldOpIntoSelect(I, SI))
317 if (isa<PHINode>(Op0))
318 if (Instruction *NV = FoldOpIntoPhi(I))
323 // (X - (X rem Y)) / Y -> X / Y; usually originates as ((X / Y) * Y) / Y
324 Value *X = 0, *Z = 0;
325 if (match(Op0, m_Sub(m_Value(X), m_Value(Z)))) { // (X - Z) / Y; Y = Op1
326 bool isSigned = I.getOpcode() == Instruction::SDiv;
327 if ((isSigned && match(Z, m_SRem(m_Specific(X), m_Specific(Op1)))) ||
328 (!isSigned && match(Z, m_URem(m_Specific(X), m_Specific(Op1)))))
329 return BinaryOperator::Create(I.getOpcode(), X, Op1);
335 Instruction *InstCombiner::visitUDiv(BinaryOperator &I) {
336 Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
338 if (Value *V = SimplifyUDivInst(Op0, Op1, TD))
339 return ReplaceInstUsesWith(I, V);
341 // Handle the integer div common cases
342 if (Instruction *Common = commonIDivTransforms(I))
345 if (ConstantInt *C = dyn_cast<ConstantInt>(Op1)) {
346 // X udiv 2^C -> X >> C
347 // Check to see if this is an unsigned division with an exact power of 2,
348 // if so, convert to a right shift.
349 if (C->getValue().isPowerOf2()) { // 0 not included in isPowerOf2
350 BinaryOperator *LShr =
351 BinaryOperator::CreateLShr(Op0,
352 ConstantInt::get(Op0->getType(), C->getValue().logBase2()));
353 if (I.isExact()) LShr->setIsExact();
357 // X udiv C, where C >= signbit
358 if (C->getValue().isNegative()) {
359 Value *IC = Builder->CreateICmpULT(Op0, C);
360 return SelectInst::Create(IC, Constant::getNullValue(I.getType()),
361 ConstantInt::get(I.getType(), 1));
365 // X udiv (C1 << N), where C1 is "1<<C2" --> X >> (N+C2)
366 { const APInt *CI; Value *N;
367 if (match(Op1, m_Shl(m_Power2(CI), m_Value(N)))) {
369 N = Builder->CreateAdd(N, ConstantInt::get(I.getType(), CI->logBase2()),
372 return BinaryOperator::CreateExactLShr(Op0, N);
373 return BinaryOperator::CreateLShr(Op0, N);
377 // udiv X, (Select Cond, C1, C2) --> Select Cond, (shr X, C1), (shr X, C2)
378 // where C1&C2 are powers of two.
379 { Value *Cond; const APInt *C1, *C2;
380 if (match(Op1, m_Select(m_Value(Cond), m_Power2(C1), m_Power2(C2)))) {
381 // Construct the "on true" case of the select
382 Value *TSI = Builder->CreateLShr(Op0, C1->logBase2(), Op1->getName()+".t",
385 // Construct the "on false" case of the select
386 Value *FSI = Builder->CreateLShr(Op0, C2->logBase2(), Op1->getName()+".f",
389 // construct the select instruction and return it.
390 return SelectInst::Create(Cond, TSI, FSI);
396 Instruction *InstCombiner::visitSDiv(BinaryOperator &I) {
397 Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
399 if (Value *V = SimplifySDivInst(Op0, Op1, TD))
400 return ReplaceInstUsesWith(I, V);
402 // Handle the integer div common cases
403 if (Instruction *Common = commonIDivTransforms(I))
406 if (ConstantInt *RHS = dyn_cast<ConstantInt>(Op1)) {
408 if (RHS->isAllOnesValue())
409 return BinaryOperator::CreateNeg(Op0);
411 // sdiv X, C --> ashr exact X, log2(C)
412 if (I.isExact() && RHS->getValue().isNonNegative() &&
413 RHS->getValue().isPowerOf2()) {
414 Value *ShAmt = llvm::ConstantInt::get(RHS->getType(),
415 RHS->getValue().exactLogBase2());
416 return BinaryOperator::CreateExactAShr(Op0, ShAmt, I.getName());
419 // -X/C --> X/-C provided the negation doesn't overflow.
420 if (SubOperator *Sub = dyn_cast<SubOperator>(Op0))
421 if (match(Sub->getOperand(0), m_Zero()) && Sub->hasNoSignedWrap())
422 return BinaryOperator::CreateSDiv(Sub->getOperand(1),
423 ConstantExpr::getNeg(RHS));
426 // If the sign bits of both operands are zero (i.e. we can prove they are
427 // unsigned inputs), turn this into a udiv.
428 if (I.getType()->isIntegerTy()) {
429 APInt Mask(APInt::getSignBit(I.getType()->getPrimitiveSizeInBits()));
430 if (MaskedValueIsZero(Op0, Mask)) {
431 if (MaskedValueIsZero(Op1, Mask)) {
432 // X sdiv Y -> X udiv Y, iff X and Y don't have sign bit set
433 return BinaryOperator::CreateUDiv(Op0, Op1, I.getName());
436 if (match(Op1, m_Shl(m_Power2(), m_Value()))) {
437 // X sdiv (1 << Y) -> X udiv (1 << Y) ( -> X u>> Y)
438 // Safe because the only negative value (1 << Y) can take on is
439 // INT_MIN, and X sdiv INT_MIN == X udiv INT_MIN == 0 if X doesn't have
441 return BinaryOperator::CreateUDiv(Op0, Op1, I.getName());
449 Instruction *InstCombiner::visitFDiv(BinaryOperator &I) {
450 Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
452 if (Value *V = SimplifyFDivInst(Op0, Op1, TD))
453 return ReplaceInstUsesWith(I, V);
455 if (ConstantFP *Op1C = dyn_cast<ConstantFP>(Op1)) {
456 const APFloat &Op1F = Op1C->getValueAPF();
458 // If the divisor has an exact multiplicative inverse we can turn the fdiv
459 // into a cheaper fmul.
460 APFloat Reciprocal(Op1F.getSemantics());
461 if (Op1F.getExactInverse(&Reciprocal)) {
462 ConstantFP *RFP = ConstantFP::get(Builder->getContext(), Reciprocal);
463 return BinaryOperator::CreateFMul(Op0, RFP);
470 /// This function implements the transforms on rem instructions that work
471 /// regardless of the kind of rem instruction it is (urem, srem, or frem). It
472 /// is used by the visitors to those instructions.
473 /// @brief Transforms common to all three rem instructions
474 Instruction *InstCombiner::commonRemTransforms(BinaryOperator &I) {
475 Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
477 if (isa<UndefValue>(Op0)) { // undef % X -> 0
478 if (I.getType()->isFPOrFPVectorTy())
479 return ReplaceInstUsesWith(I, Op0); // X % undef -> undef (could be SNaN)
480 return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
482 if (isa<UndefValue>(Op1))
483 return ReplaceInstUsesWith(I, Op1); // X % undef -> undef
485 // Handle cases involving: rem X, (select Cond, Y, Z)
486 if (isa<SelectInst>(Op1) && SimplifyDivRemOfSelect(I))
492 /// This function implements the transforms common to both integer remainder
493 /// instructions (urem and srem). It is called by the visitors to those integer
494 /// remainder instructions.
495 /// @brief Common integer remainder transforms
496 Instruction *InstCombiner::commonIRemTransforms(BinaryOperator &I) {
497 Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
499 if (Instruction *common = commonRemTransforms(I))
504 return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
506 // 0 % X == 0 for integer, we don't need to preserve faults!
507 if (Constant *LHS = dyn_cast<Constant>(Op0))
508 if (LHS->isNullValue())
509 return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
511 if (ConstantInt *RHS = dyn_cast<ConstantInt>(Op1)) {
512 // X % 0 == undef, we don't need to preserve faults!
513 if (RHS->equalsInt(0))
514 return ReplaceInstUsesWith(I, UndefValue::get(I.getType()));
516 if (RHS->equalsInt(1)) // X % 1 == 0
517 return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
519 if (Instruction *Op0I = dyn_cast<Instruction>(Op0)) {
520 if (SelectInst *SI = dyn_cast<SelectInst>(Op0I)) {
521 if (Instruction *R = FoldOpIntoSelect(I, SI))
523 } else if (isa<PHINode>(Op0I)) {
524 if (Instruction *NV = FoldOpIntoPhi(I))
528 // See if we can fold away this rem instruction.
529 if (SimplifyDemandedInstructionBits(I))
537 Instruction *InstCombiner::visitURem(BinaryOperator &I) {
538 Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
540 if (Instruction *common = commonIRemTransforms(I))
543 // X urem C^2 -> X and C-1
545 if (match(Op1, m_Power2(C)))
546 return BinaryOperator::CreateAnd(Op0,
547 ConstantInt::get(I.getType(), *C-1));
550 // Turn A % (C << N), where C is 2^k, into A & ((C << N)-1)
551 if (match(Op1, m_Shl(m_Power2(), m_Value()))) {
552 Constant *N1 = Constant::getAllOnesValue(I.getType());
553 Value *Add = Builder->CreateAdd(Op1, N1, "tmp");
554 return BinaryOperator::CreateAnd(Op0, Add);
557 // urem X, (select Cond, 2^C1, 2^C2) -->
558 // select Cond, (and X, C1-1), (and X, C2-1)
559 // when C1&C2 are powers of two.
560 { Value *Cond; const APInt *C1, *C2;
561 if (match(Op1, m_Select(m_Value(Cond), m_Power2(C1), m_Power2(C2)))) {
562 Value *TrueAnd = Builder->CreateAnd(Op0, *C1-1, Op1->getName()+".t");
563 Value *FalseAnd = Builder->CreateAnd(Op0, *C2-1, Op1->getName()+".f");
564 return SelectInst::Create(Cond, TrueAnd, FalseAnd);
571 Instruction *InstCombiner::visitSRem(BinaryOperator &I) {
572 Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
574 // Handle the integer rem common cases
575 if (Instruction *Common = commonIRemTransforms(I))
578 if (Value *RHSNeg = dyn_castNegVal(Op1))
579 if (!isa<Constant>(RHSNeg) ||
580 (isa<ConstantInt>(RHSNeg) &&
581 cast<ConstantInt>(RHSNeg)->getValue().isStrictlyPositive())) {
583 Worklist.AddValue(I.getOperand(1));
584 I.setOperand(1, RHSNeg);
588 // If the sign bits of both operands are zero (i.e. we can prove they are
589 // unsigned inputs), turn this into a urem.
590 if (I.getType()->isIntegerTy()) {
591 APInt Mask(APInt::getSignBit(I.getType()->getPrimitiveSizeInBits()));
592 if (MaskedValueIsZero(Op1, Mask) && MaskedValueIsZero(Op0, Mask)) {
593 // X srem Y -> X urem Y, iff X and Y don't have sign bit set
594 return BinaryOperator::CreateURem(Op0, Op1, I.getName());
598 // If it's a constant vector, flip any negative values positive.
599 if (ConstantVector *RHSV = dyn_cast<ConstantVector>(Op1)) {
600 unsigned VWidth = RHSV->getNumOperands();
602 bool hasNegative = false;
603 for (unsigned i = 0; !hasNegative && i != VWidth; ++i)
604 if (ConstantInt *RHS = dyn_cast<ConstantInt>(RHSV->getOperand(i)))
605 if (RHS->getValue().isNegative())
609 std::vector<Constant *> Elts(VWidth);
610 for (unsigned i = 0; i != VWidth; ++i) {
611 if (ConstantInt *RHS = dyn_cast<ConstantInt>(RHSV->getOperand(i))) {
612 if (RHS->getValue().isNegative())
613 Elts[i] = cast<ConstantInt>(ConstantExpr::getNeg(RHS));
619 Constant *NewRHSV = ConstantVector::get(Elts);
620 if (NewRHSV != RHSV) {
621 Worklist.AddValue(I.getOperand(1));
622 I.setOperand(1, NewRHSV);
631 Instruction *InstCombiner::visitFRem(BinaryOperator &I) {
632 return commonRemTransforms(I);