1 //===- CorrelatedValuePropagation.cpp - Propagate CFG-derived info --------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file implements the Correlated Value Propagation pass.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/Transforms/Scalar/CorrelatedValuePropagation.h"
14 #include "llvm/ADT/DepthFirstIterator.h"
15 #include "llvm/ADT/SmallVector.h"
16 #include "llvm/ADT/Statistic.h"
17 #include "llvm/Analysis/DomTreeUpdater.h"
18 #include "llvm/Analysis/GlobalsModRef.h"
19 #include "llvm/Analysis/InstructionSimplify.h"
20 #include "llvm/Analysis/LazyValueInfo.h"
21 #include "llvm/Analysis/ValueTracking.h"
22 #include "llvm/IR/Attributes.h"
23 #include "llvm/IR/BasicBlock.h"
24 #include "llvm/IR/CFG.h"
25 #include "llvm/IR/Constant.h"
26 #include "llvm/IR/ConstantRange.h"
27 #include "llvm/IR/Constants.h"
28 #include "llvm/IR/DerivedTypes.h"
29 #include "llvm/IR/Function.h"
30 #include "llvm/IR/IRBuilder.h"
31 #include "llvm/IR/InstrTypes.h"
32 #include "llvm/IR/Instruction.h"
33 #include "llvm/IR/Instructions.h"
34 #include "llvm/IR/IntrinsicInst.h"
35 #include "llvm/IR/Operator.h"
36 #include "llvm/IR/PassManager.h"
37 #include "llvm/IR/Type.h"
38 #include "llvm/IR/Value.h"
39 #include "llvm/Support/Casting.h"
40 #include "llvm/Support/CommandLine.h"
41 #include "llvm/Transforms/Utils/Local.h"
48 #define DEBUG_TYPE "correlated-value-propagation"
50 static cl::opt
<bool> CanonicalizeICmpPredicatesToUnsigned(
51 "canonicalize-icmp-predicates-to-unsigned", cl::init(true), cl::Hidden
,
52 cl::desc("Enables canonicalization of signed relational predicates to "
53 "unsigned (e.g. sgt => ugt)"));
55 STATISTIC(NumPhis
, "Number of phis propagated");
56 STATISTIC(NumPhiCommon
, "Number of phis deleted via common incoming value");
57 STATISTIC(NumSelects
, "Number of selects propagated");
58 STATISTIC(NumCmps
, "Number of comparisons propagated");
59 STATISTIC(NumReturns
, "Number of return values propagated");
60 STATISTIC(NumDeadCases
, "Number of switch cases removed");
61 STATISTIC(NumSDivSRemsNarrowed
,
62 "Number of sdivs/srems whose width was decreased");
63 STATISTIC(NumSDivs
, "Number of sdiv converted to udiv");
64 STATISTIC(NumUDivURemsNarrowed
,
65 "Number of udivs/urems whose width was decreased");
66 STATISTIC(NumAShrsConverted
, "Number of ashr converted to lshr");
67 STATISTIC(NumAShrsRemoved
, "Number of ashr removed");
68 STATISTIC(NumSRems
, "Number of srem converted to urem");
69 STATISTIC(NumSExt
, "Number of sext converted to zext");
70 STATISTIC(NumSICmps
, "Number of signed icmp preds simplified to unsigned");
71 STATISTIC(NumAnd
, "Number of ands removed");
72 STATISTIC(NumNW
, "Number of no-wrap deductions");
73 STATISTIC(NumNSW
, "Number of no-signed-wrap deductions");
74 STATISTIC(NumNUW
, "Number of no-unsigned-wrap deductions");
75 STATISTIC(NumAddNW
, "Number of no-wrap deductions for add");
76 STATISTIC(NumAddNSW
, "Number of no-signed-wrap deductions for add");
77 STATISTIC(NumAddNUW
, "Number of no-unsigned-wrap deductions for add");
78 STATISTIC(NumSubNW
, "Number of no-wrap deductions for sub");
79 STATISTIC(NumSubNSW
, "Number of no-signed-wrap deductions for sub");
80 STATISTIC(NumSubNUW
, "Number of no-unsigned-wrap deductions for sub");
81 STATISTIC(NumMulNW
, "Number of no-wrap deductions for mul");
82 STATISTIC(NumMulNSW
, "Number of no-signed-wrap deductions for mul");
83 STATISTIC(NumMulNUW
, "Number of no-unsigned-wrap deductions for mul");
84 STATISTIC(NumShlNW
, "Number of no-wrap deductions for shl");
85 STATISTIC(NumShlNSW
, "Number of no-signed-wrap deductions for shl");
86 STATISTIC(NumShlNUW
, "Number of no-unsigned-wrap deductions for shl");
87 STATISTIC(NumAbs
, "Number of llvm.abs intrinsics removed");
88 STATISTIC(NumOverflows
, "Number of overflow checks removed");
89 STATISTIC(NumSaturating
,
90 "Number of saturating arithmetics converted to normal arithmetics");
91 STATISTIC(NumNonNull
, "Number of function pointer arguments marked non-null");
92 STATISTIC(NumMinMax
, "Number of llvm.[us]{min,max} intrinsics removed");
93 STATISTIC(NumUDivURemsNarrowedExpanded
,
94 "Number of bound udiv's/urem's expanded");
95 STATISTIC(NumZExt
, "Number of non-negative deductions");
97 static Constant
*getConstantAt(Value
*V
, Instruction
*At
, LazyValueInfo
*LVI
) {
98 if (Constant
*C
= LVI
->getConstant(V
, At
))
101 // TODO: The following really should be sunk inside LVI's core algorithm, or
102 // at least the outer shims around such.
103 auto *C
= dyn_cast
<CmpInst
>(V
);
107 Value
*Op0
= C
->getOperand(0);
108 Constant
*Op1
= dyn_cast
<Constant
>(C
->getOperand(1));
112 LazyValueInfo::Tristate Result
= LVI
->getPredicateAt(
113 C
->getPredicate(), Op0
, Op1
, At
, /*UseBlockValue=*/false);
114 if (Result
== LazyValueInfo::Unknown
)
117 return (Result
== LazyValueInfo::True
)
118 ? ConstantInt::getTrue(C
->getContext())
119 : ConstantInt::getFalse(C
->getContext());
122 static bool processSelect(SelectInst
*S
, LazyValueInfo
*LVI
) {
123 if (S
->getType()->isVectorTy() || isa
<Constant
>(S
->getCondition()))
126 bool Changed
= false;
127 for (Use
&U
: make_early_inc_range(S
->uses())) {
128 auto *I
= cast
<Instruction
>(U
.getUser());
130 if (auto *PN
= dyn_cast
<PHINode
>(I
))
131 C
= LVI
->getConstantOnEdge(S
->getCondition(), PN
->getIncomingBlock(U
),
134 C
= getConstantAt(S
->getCondition(), I
, LVI
);
136 auto *CI
= dyn_cast_or_null
<ConstantInt
>(C
);
140 U
.set(CI
->isOne() ? S
->getTrueValue() : S
->getFalseValue());
145 if (Changed
&& S
->use_empty())
146 S
->eraseFromParent();
151 /// Try to simplify a phi with constant incoming values that match the edge
152 /// values of a non-constant value on all other edges:
154 /// %isnull = icmp eq i8* %x, null
155 /// br i1 %isnull, label %bb2, label %bb1
159 /// %r = phi i8* [ %x, %bb1 ], [ null, %bb0 ]
162 static bool simplifyCommonValuePhi(PHINode
*P
, LazyValueInfo
*LVI
,
164 // Collect incoming constants and initialize possible common value.
165 SmallVector
<std::pair
<Constant
*, unsigned>, 4> IncomingConstants
;
166 Value
*CommonValue
= nullptr;
167 for (unsigned i
= 0, e
= P
->getNumIncomingValues(); i
!= e
; ++i
) {
168 Value
*Incoming
= P
->getIncomingValue(i
);
169 if (auto *IncomingConstant
= dyn_cast
<Constant
>(Incoming
)) {
170 IncomingConstants
.push_back(std::make_pair(IncomingConstant
, i
));
171 } else if (!CommonValue
) {
172 // The potential common value is initialized to the first non-constant.
173 CommonValue
= Incoming
;
174 } else if (Incoming
!= CommonValue
) {
175 // There can be only one non-constant common value.
180 if (!CommonValue
|| IncomingConstants
.empty())
183 // The common value must be valid in all incoming blocks.
184 BasicBlock
*ToBB
= P
->getParent();
185 if (auto *CommonInst
= dyn_cast
<Instruction
>(CommonValue
))
186 if (!DT
->dominates(CommonInst
, ToBB
))
189 // We have a phi with exactly 1 variable incoming value and 1 or more constant
190 // incoming values. See if all constant incoming values can be mapped back to
191 // the same incoming variable value.
192 for (auto &IncomingConstant
: IncomingConstants
) {
193 Constant
*C
= IncomingConstant
.first
;
194 BasicBlock
*IncomingBB
= P
->getIncomingBlock(IncomingConstant
.second
);
195 if (C
!= LVI
->getConstantOnEdge(CommonValue
, IncomingBB
, ToBB
, P
))
199 // LVI only guarantees that the value matches a certain constant if the value
200 // is not poison. Make sure we don't replace a well-defined value with poison.
201 // This is usually satisfied due to a prior branch on the value.
202 if (!isGuaranteedNotToBePoison(CommonValue
, nullptr, P
, DT
))
205 // All constant incoming values map to the same variable along the incoming
206 // edges of the phi. The phi is unnecessary.
207 P
->replaceAllUsesWith(CommonValue
);
208 P
->eraseFromParent();
213 static Value
*getValueOnEdge(LazyValueInfo
*LVI
, Value
*Incoming
,
214 BasicBlock
*From
, BasicBlock
*To
,
216 if (Constant
*C
= LVI
->getConstantOnEdge(Incoming
, From
, To
, CxtI
))
219 // Look if the incoming value is a select with a scalar condition for which
220 // LVI can tells us the value. In that case replace the incoming value with
221 // the appropriate value of the select. This often allows us to remove the
223 auto *SI
= dyn_cast
<SelectInst
>(Incoming
);
227 // Once LVI learns to handle vector types, we could also add support
228 // for vector type constants that are not all zeroes or all ones.
229 Value
*Condition
= SI
->getCondition();
230 if (!Condition
->getType()->isVectorTy()) {
231 if (Constant
*C
= LVI
->getConstantOnEdge(Condition
, From
, To
, CxtI
)) {
233 return SI
->getTrueValue();
234 if (C
->isZeroValue())
235 return SI
->getFalseValue();
239 // Look if the select has a constant but LVI tells us that the incoming
240 // value can never be that constant. In that case replace the incoming
241 // value with the other value of the select. This often allows us to
242 // remove the select later.
245 if (auto *C
= dyn_cast
<Constant
>(SI
->getFalseValue()))
246 if (LVI
->getPredicateOnEdge(ICmpInst::ICMP_EQ
, SI
, C
, From
, To
, CxtI
) ==
247 LazyValueInfo::False
)
248 return SI
->getTrueValue();
251 // similar to the select "false" case, but try the select "true" value
252 if (auto *C
= dyn_cast
<Constant
>(SI
->getTrueValue()))
253 if (LVI
->getPredicateOnEdge(ICmpInst::ICMP_EQ
, SI
, C
, From
, To
, CxtI
) ==
254 LazyValueInfo::False
)
255 return SI
->getFalseValue();
260 static bool processPHI(PHINode
*P
, LazyValueInfo
*LVI
, DominatorTree
*DT
,
261 const SimplifyQuery
&SQ
) {
262 bool Changed
= false;
264 BasicBlock
*BB
= P
->getParent();
265 for (unsigned i
= 0, e
= P
->getNumIncomingValues(); i
< e
; ++i
) {
266 Value
*Incoming
= P
->getIncomingValue(i
);
267 if (isa
<Constant
>(Incoming
)) continue;
269 Value
*V
= getValueOnEdge(LVI
, Incoming
, P
->getIncomingBlock(i
), BB
, P
);
271 P
->setIncomingValue(i
, V
);
276 if (Value
*V
= simplifyInstruction(P
, SQ
)) {
277 P
->replaceAllUsesWith(V
);
278 P
->eraseFromParent();
283 Changed
= simplifyCommonValuePhi(P
, LVI
, DT
);
291 static bool processICmp(ICmpInst
*Cmp
, LazyValueInfo
*LVI
) {
292 if (!CanonicalizeICmpPredicatesToUnsigned
)
295 // Only for signed relational comparisons of scalar integers.
296 if (Cmp
->getType()->isVectorTy() ||
297 !Cmp
->getOperand(0)->getType()->isIntegerTy())
300 if (!Cmp
->isSigned())
303 ICmpInst::Predicate UnsignedPred
=
304 ConstantRange::getEquivalentPredWithFlippedSignedness(
306 LVI
->getConstantRangeAtUse(Cmp
->getOperandUse(0),
307 /*UndefAllowed*/ true),
308 LVI
->getConstantRangeAtUse(Cmp
->getOperandUse(1),
309 /*UndefAllowed*/ true));
311 if (UnsignedPred
== ICmpInst::Predicate::BAD_ICMP_PREDICATE
)
315 Cmp
->setPredicate(UnsignedPred
);
320 /// See if LazyValueInfo's ability to exploit edge conditions or range
321 /// information is sufficient to prove this comparison. Even for local
322 /// conditions, this can sometimes prove conditions instcombine can't by
323 /// exploiting range information.
324 static bool constantFoldCmp(CmpInst
*Cmp
, LazyValueInfo
*LVI
) {
325 Value
*Op0
= Cmp
->getOperand(0);
326 Value
*Op1
= Cmp
->getOperand(1);
327 LazyValueInfo::Tristate Result
=
328 LVI
->getPredicateAt(Cmp
->getPredicate(), Op0
, Op1
, Cmp
,
329 /*UseBlockValue=*/true);
330 if (Result
== LazyValueInfo::Unknown
)
335 ConstantInt::get(CmpInst::makeCmpResultType(Op0
->getType()), Result
);
336 Cmp
->replaceAllUsesWith(TorF
);
337 Cmp
->eraseFromParent();
341 static bool processCmp(CmpInst
*Cmp
, LazyValueInfo
*LVI
) {
342 if (constantFoldCmp(Cmp
, LVI
))
345 if (auto *ICmp
= dyn_cast
<ICmpInst
>(Cmp
))
346 if (processICmp(ICmp
, LVI
))
352 /// Simplify a switch instruction by removing cases which can never fire. If the
353 /// uselessness of a case could be determined locally then constant propagation
354 /// would already have figured it out. Instead, walk the predecessors and
355 /// statically evaluate cases based on information available on that edge. Cases
356 /// that cannot fire no matter what the incoming edge can safely be removed. If
357 /// a case fires on every incoming edge then the entire switch can be removed
358 /// and replaced with a branch to the case destination.
359 static bool processSwitch(SwitchInst
*I
, LazyValueInfo
*LVI
,
361 DomTreeUpdater
DTU(*DT
, DomTreeUpdater::UpdateStrategy::Lazy
);
362 Value
*Cond
= I
->getCondition();
363 BasicBlock
*BB
= I
->getParent();
365 // Analyse each switch case in turn.
366 bool Changed
= false;
367 DenseMap
<BasicBlock
*, int> SuccessorsCount
;
368 for (auto *Succ
: successors(BB
))
369 SuccessorsCount
[Succ
]++;
371 { // Scope for SwitchInstProfUpdateWrapper. It must not live during
372 // ConstantFoldTerminator() as the underlying SwitchInst can be changed.
373 SwitchInstProfUpdateWrapper
SI(*I
);
375 for (auto CI
= SI
->case_begin(), CE
= SI
->case_end(); CI
!= CE
;) {
376 ConstantInt
*Case
= CI
->getCaseValue();
377 LazyValueInfo::Tristate State
=
378 LVI
->getPredicateAt(CmpInst::ICMP_EQ
, Cond
, Case
, I
,
379 /* UseBlockValue */ true);
381 if (State
== LazyValueInfo::False
) {
382 // This case never fires - remove it.
383 BasicBlock
*Succ
= CI
->getCaseSuccessor();
384 Succ
->removePredecessor(BB
);
385 CI
= SI
.removeCase(CI
);
388 // The condition can be modified by removePredecessor's PHI simplification
390 Cond
= SI
->getCondition();
394 if (--SuccessorsCount
[Succ
] == 0)
395 DTU
.applyUpdatesPermissive({{DominatorTree::Delete
, BB
, Succ
}});
398 if (State
== LazyValueInfo::True
) {
399 // This case always fires. Arrange for the switch to be turned into an
400 // unconditional branch by replacing the switch condition with the case
402 SI
->setCondition(Case
);
403 NumDeadCases
+= SI
->getNumCases();
408 // Increment the case iterator since we didn't delete it.
414 // If the switch has been simplified to the point where it can be replaced
415 // by a branch then do so now.
416 ConstantFoldTerminator(BB
, /*DeleteDeadConditions = */ false,
417 /*TLI = */ nullptr, &DTU
);
421 // See if we can prove that the given binary op intrinsic will not overflow.
422 static bool willNotOverflow(BinaryOpIntrinsic
*BO
, LazyValueInfo
*LVI
) {
423 ConstantRange LRange
=
424 LVI
->getConstantRangeAtUse(BO
->getOperandUse(0), /*UndefAllowed*/ false);
425 ConstantRange RRange
=
426 LVI
->getConstantRangeAtUse(BO
->getOperandUse(1), /*UndefAllowed*/ false);
427 ConstantRange NWRegion
= ConstantRange::makeGuaranteedNoWrapRegion(
428 BO
->getBinaryOp(), RRange
, BO
->getNoWrapKind());
429 return NWRegion
.contains(LRange
);
432 static void setDeducedOverflowingFlags(Value
*V
, Instruction::BinaryOps Opcode
,
433 bool NewNSW
, bool NewNUW
) {
434 Statistic
*OpcNW
, *OpcNSW
, *OpcNUW
;
436 case Instruction::Add
:
441 case Instruction::Sub
:
446 case Instruction::Mul
:
451 case Instruction::Shl
:
457 llvm_unreachable("Will not be called with other binops");
460 auto *Inst
= dyn_cast
<Instruction
>(V
);
467 Inst
->setHasNoSignedWrap();
475 Inst
->setHasNoUnsignedWrap();
479 static bool processBinOp(BinaryOperator
*BinOp
, LazyValueInfo
*LVI
);
481 // See if @llvm.abs argument is alays positive/negative, and simplify.
482 // Notably, INT_MIN can belong to either range, regardless of the NSW,
483 // because it is negation-invariant.
484 static bool processAbsIntrinsic(IntrinsicInst
*II
, LazyValueInfo
*LVI
) {
485 Value
*X
= II
->getArgOperand(0);
486 Type
*Ty
= X
->getType();
487 if (!Ty
->isIntegerTy())
490 bool IsIntMinPoison
= cast
<ConstantInt
>(II
->getArgOperand(1))->isOne();
491 APInt IntMin
= APInt::getSignedMinValue(Ty
->getScalarSizeInBits());
492 ConstantRange Range
= LVI
->getConstantRangeAtUse(
493 II
->getOperandUse(0), /*UndefAllowed*/ IsIntMinPoison
);
495 // Is X in [0, IntMin]? NOTE: INT_MIN is fine!
496 if (Range
.icmp(CmpInst::ICMP_ULE
, IntMin
)) {
498 II
->replaceAllUsesWith(X
);
499 II
->eraseFromParent();
503 // Is X in [IntMin, 0]? NOTE: INT_MIN is fine!
504 if (Range
.getSignedMax().isNonPositive()) {
506 Value
*NegX
= B
.CreateNeg(X
, II
->getName(), /*HasNUW=*/false,
507 /*HasNSW=*/IsIntMinPoison
);
509 II
->replaceAllUsesWith(NegX
);
510 II
->eraseFromParent();
512 // See if we can infer some no-wrap flags.
513 if (auto *BO
= dyn_cast
<BinaryOperator
>(NegX
))
514 processBinOp(BO
, LVI
);
519 // Argument's range crosses zero.
520 // Can we at least tell that the argument is never INT_MIN?
521 if (!IsIntMinPoison
&& !Range
.contains(IntMin
)) {
524 II
->setArgOperand(1, ConstantInt::getTrue(II
->getContext()));
530 // See if this min/max intrinsic always picks it's one specific operand.
531 static bool processMinMaxIntrinsic(MinMaxIntrinsic
*MM
, LazyValueInfo
*LVI
) {
532 CmpInst::Predicate Pred
= CmpInst::getNonStrictPredicate(MM
->getPredicate());
533 LazyValueInfo::Tristate Result
= LVI
->getPredicateAt(
534 Pred
, MM
->getLHS(), MM
->getRHS(), MM
, /*UseBlockValue=*/true);
535 if (Result
== LazyValueInfo::Unknown
)
539 MM
->replaceAllUsesWith(MM
->getOperand(!Result
));
540 MM
->eraseFromParent();
544 // Rewrite this with.overflow intrinsic as non-overflowing.
545 static bool processOverflowIntrinsic(WithOverflowInst
*WO
, LazyValueInfo
*LVI
) {
547 Instruction::BinaryOps Opcode
= WO
->getBinaryOp();
548 bool NSW
= WO
->isSigned();
549 bool NUW
= !WO
->isSigned();
552 B
.CreateBinOp(Opcode
, WO
->getLHS(), WO
->getRHS(), WO
->getName());
553 setDeducedOverflowingFlags(NewOp
, Opcode
, NSW
, NUW
);
555 StructType
*ST
= cast
<StructType
>(WO
->getType());
556 Constant
*Struct
= ConstantStruct::get(ST
,
557 { PoisonValue::get(ST
->getElementType(0)),
558 ConstantInt::getFalse(ST
->getElementType(1)) });
559 Value
*NewI
= B
.CreateInsertValue(Struct
, NewOp
, 0);
560 WO
->replaceAllUsesWith(NewI
);
561 WO
->eraseFromParent();
564 // See if we can infer the other no-wrap too.
565 if (auto *BO
= dyn_cast
<BinaryOperator
>(NewOp
))
566 processBinOp(BO
, LVI
);
571 static bool processSaturatingInst(SaturatingInst
*SI
, LazyValueInfo
*LVI
) {
572 Instruction::BinaryOps Opcode
= SI
->getBinaryOp();
573 bool NSW
= SI
->isSigned();
574 bool NUW
= !SI
->isSigned();
575 BinaryOperator
*BinOp
= BinaryOperator::Create(
576 Opcode
, SI
->getLHS(), SI
->getRHS(), SI
->getName(), SI
);
577 BinOp
->setDebugLoc(SI
->getDebugLoc());
578 setDeducedOverflowingFlags(BinOp
, Opcode
, NSW
, NUW
);
580 SI
->replaceAllUsesWith(BinOp
);
581 SI
->eraseFromParent();
584 // See if we can infer the other no-wrap too.
585 if (auto *BO
= dyn_cast
<BinaryOperator
>(BinOp
))
586 processBinOp(BO
, LVI
);
591 /// Infer nonnull attributes for the arguments at the specified callsite.
592 static bool processCallSite(CallBase
&CB
, LazyValueInfo
*LVI
) {
594 if (CB
.getIntrinsicID() == Intrinsic::abs
) {
595 return processAbsIntrinsic(&cast
<IntrinsicInst
>(CB
), LVI
);
598 if (auto *MM
= dyn_cast
<MinMaxIntrinsic
>(&CB
)) {
599 return processMinMaxIntrinsic(MM
, LVI
);
602 if (auto *WO
= dyn_cast
<WithOverflowInst
>(&CB
)) {
603 if (WO
->getLHS()->getType()->isIntegerTy() && willNotOverflow(WO
, LVI
)) {
604 return processOverflowIntrinsic(WO
, LVI
);
608 if (auto *SI
= dyn_cast
<SaturatingInst
>(&CB
)) {
609 if (SI
->getType()->isIntegerTy() && willNotOverflow(SI
, LVI
)) {
610 return processSaturatingInst(SI
, LVI
);
614 bool Changed
= false;
616 // Deopt bundle operands are intended to capture state with minimal
617 // perturbance of the code otherwise. If we can find a constant value for
618 // any such operand and remove a use of the original value, that's
619 // desireable since it may allow further optimization of that value (e.g. via
620 // single use rules in instcombine). Since deopt uses tend to,
621 // idiomatically, appear along rare conditional paths, it's reasonable likely
622 // we may have a conditional fact with which LVI can fold.
623 if (auto DeoptBundle
= CB
.getOperandBundle(LLVMContext::OB_deopt
)) {
624 for (const Use
&ConstU
: DeoptBundle
->Inputs
) {
625 Use
&U
= const_cast<Use
&>(ConstU
);
627 if (V
->getType()->isVectorTy()) continue;
628 if (isa
<Constant
>(V
)) continue;
630 Constant
*C
= LVI
->getConstant(V
, &CB
);
637 SmallVector
<unsigned, 4> ArgNos
;
640 for (Value
*V
: CB
.args()) {
641 PointerType
*Type
= dyn_cast
<PointerType
>(V
->getType());
642 // Try to mark pointer typed parameters as non-null. We skip the
643 // relatively expensive analysis for constants which are obviously either
644 // null or non-null to start with.
645 if (Type
&& !CB
.paramHasAttr(ArgNo
, Attribute::NonNull
) &&
647 LVI
->getPredicateAt(ICmpInst::ICMP_EQ
, V
,
648 ConstantPointerNull::get(Type
), &CB
,
649 /*UseBlockValue=*/false) == LazyValueInfo::False
)
650 ArgNos
.push_back(ArgNo
);
654 assert(ArgNo
== CB
.arg_size() && "Call arguments not processed correctly.");
659 NumNonNull
+= ArgNos
.size();
660 AttributeList AS
= CB
.getAttributes();
661 LLVMContext
&Ctx
= CB
.getContext();
662 AS
= AS
.addParamAttribute(Ctx
, ArgNos
,
663 Attribute::get(Ctx
, Attribute::NonNull
));
664 CB
.setAttributes(AS
);
669 enum class Domain
{ NonNegative
, NonPositive
, Unknown
};
671 static Domain
getDomain(const ConstantRange
&CR
) {
672 if (CR
.isAllNonNegative())
673 return Domain::NonNegative
;
674 if (CR
.icmp(ICmpInst::ICMP_SLE
, APInt::getZero(CR
.getBitWidth())))
675 return Domain::NonPositive
;
676 return Domain::Unknown
;
679 /// Try to shrink a sdiv/srem's width down to the smallest power of two that's
680 /// sufficient to contain its operands.
681 static bool narrowSDivOrSRem(BinaryOperator
*Instr
, const ConstantRange
&LCR
,
682 const ConstantRange
&RCR
) {
683 assert(Instr
->getOpcode() == Instruction::SDiv
||
684 Instr
->getOpcode() == Instruction::SRem
);
685 assert(!Instr
->getType()->isVectorTy());
687 // Find the smallest power of two bitwidth that's sufficient to hold Instr's
689 unsigned OrigWidth
= Instr
->getType()->getIntegerBitWidth();
691 // What is the smallest bit width that can accommodate the entire value ranges
692 // of both of the operands?
693 unsigned MinSignedBits
=
694 std::max(LCR
.getMinSignedBits(), RCR
.getMinSignedBits());
696 // sdiv/srem is UB if divisor is -1 and divident is INT_MIN, so unless we can
697 // prove that such a combination is impossible, we need to bump the bitwidth.
698 if (RCR
.contains(APInt::getAllOnes(OrigWidth
)) &&
699 LCR
.contains(APInt::getSignedMinValue(MinSignedBits
).sext(OrigWidth
)))
702 // Don't shrink below 8 bits wide.
703 unsigned NewWidth
= std::max
<unsigned>(PowerOf2Ceil(MinSignedBits
), 8);
705 // NewWidth might be greater than OrigWidth if OrigWidth is not a power of
707 if (NewWidth
>= OrigWidth
)
710 ++NumSDivSRemsNarrowed
;
711 IRBuilder
<> B
{Instr
};
712 auto *TruncTy
= Type::getIntNTy(Instr
->getContext(), NewWidth
);
713 auto *LHS
= B
.CreateTruncOrBitCast(Instr
->getOperand(0), TruncTy
,
714 Instr
->getName() + ".lhs.trunc");
715 auto *RHS
= B
.CreateTruncOrBitCast(Instr
->getOperand(1), TruncTy
,
716 Instr
->getName() + ".rhs.trunc");
717 auto *BO
= B
.CreateBinOp(Instr
->getOpcode(), LHS
, RHS
, Instr
->getName());
718 auto *Sext
= B
.CreateSExt(BO
, Instr
->getType(), Instr
->getName() + ".sext");
719 if (auto *BinOp
= dyn_cast
<BinaryOperator
>(BO
))
720 if (BinOp
->getOpcode() == Instruction::SDiv
)
721 BinOp
->setIsExact(Instr
->isExact());
723 Instr
->replaceAllUsesWith(Sext
);
724 Instr
->eraseFromParent();
728 static bool expandUDivOrURem(BinaryOperator
*Instr
, const ConstantRange
&XCR
,
729 const ConstantRange
&YCR
) {
730 Type
*Ty
= Instr
->getType();
731 assert(Instr
->getOpcode() == Instruction::UDiv
||
732 Instr
->getOpcode() == Instruction::URem
);
733 assert(!Ty
->isVectorTy());
734 bool IsRem
= Instr
->getOpcode() == Instruction::URem
;
736 Value
*X
= Instr
->getOperand(0);
737 Value
*Y
= Instr
->getOperand(1);
739 // X u/ Y -> 0 iff X u< Y
740 // X u% Y -> X iff X u< Y
741 if (XCR
.icmp(ICmpInst::ICMP_ULT
, YCR
)) {
742 Instr
->replaceAllUsesWith(IsRem
? X
: Constant::getNullValue(Ty
));
743 Instr
->eraseFromParent();
744 ++NumUDivURemsNarrowedExpanded
;
750 // We can represent the modulo operation as a loop/self-recursion:
756 // ret urem_rec(Z, Y)
757 // which isn't better, but if we only need a single iteration
758 // to compute the answer, this becomes quite good:
759 // R = X < Y ? X : X - Y iff X u< 2*Y (w/ unsigned saturation)
760 // Now, we do not care about all full multiples of Y in X, they do not change
761 // the answer, thus we could rewrite the expression as:
762 // X* = X - (Y * |_ X / Y _|)
764 // so we don't need the *first* iteration to return, we just need to
765 // know *which* iteration will always return, so we could also rewrite it as:
766 // X* = X - (Y * |_ X / Y _|)
767 // R = X* % Y iff X* u< 2*Y (w/ unsigned saturation)
768 // but that does not seem profitable here.
770 // Even if we don't know X's range, the divisor may be so large, X can't ever
771 // be 2x larger than that. I.e. if divisor is always negative.
772 if (!XCR
.icmp(ICmpInst::ICMP_ULT
,
773 YCR
.umul_sat(APInt(YCR
.getBitWidth(), 2))) &&
774 !YCR
.isAllNegative())
777 IRBuilder
<> B(Instr
);
779 if (XCR
.icmp(ICmpInst::ICMP_UGE
, YCR
)) {
780 // If X is between Y and 2*Y the result is known.
782 ExpandedOp
= B
.CreateNUWSub(X
, Y
);
784 ExpandedOp
= ConstantInt::get(Instr
->getType(), 1);
786 // NOTE: this transformation introduces two uses of X,
787 // but it may be undef so we must freeze it first.
789 if (!isGuaranteedNotToBeUndef(X
))
790 FrozenX
= B
.CreateFreeze(X
, X
->getName() + ".frozen");
791 auto *AdjX
= B
.CreateNUWSub(FrozenX
, Y
, Instr
->getName() + ".urem");
793 B
.CreateICmp(ICmpInst::ICMP_ULT
, FrozenX
, Y
, Instr
->getName() + ".cmp");
794 ExpandedOp
= B
.CreateSelect(Cmp
, FrozenX
, AdjX
);
797 B
.CreateICmp(ICmpInst::ICMP_UGE
, X
, Y
, Instr
->getName() + ".cmp");
798 ExpandedOp
= B
.CreateZExt(Cmp
, Ty
, Instr
->getName() + ".udiv");
800 ExpandedOp
->takeName(Instr
);
801 Instr
->replaceAllUsesWith(ExpandedOp
);
802 Instr
->eraseFromParent();
803 ++NumUDivURemsNarrowedExpanded
;
807 /// Try to shrink a udiv/urem's width down to the smallest power of two that's
808 /// sufficient to contain its operands.
809 static bool narrowUDivOrURem(BinaryOperator
*Instr
, const ConstantRange
&XCR
,
810 const ConstantRange
&YCR
) {
811 assert(Instr
->getOpcode() == Instruction::UDiv
||
812 Instr
->getOpcode() == Instruction::URem
);
813 assert(!Instr
->getType()->isVectorTy());
815 // Find the smallest power of two bitwidth that's sufficient to hold Instr's
818 // What is the smallest bit width that can accommodate the entire value ranges
819 // of both of the operands?
820 unsigned MaxActiveBits
= std::max(XCR
.getActiveBits(), YCR
.getActiveBits());
821 // Don't shrink below 8 bits wide.
822 unsigned NewWidth
= std::max
<unsigned>(PowerOf2Ceil(MaxActiveBits
), 8);
824 // NewWidth might be greater than OrigWidth if OrigWidth is not a power of
826 if (NewWidth
>= Instr
->getType()->getIntegerBitWidth())
829 ++NumUDivURemsNarrowed
;
830 IRBuilder
<> B
{Instr
};
831 auto *TruncTy
= Type::getIntNTy(Instr
->getContext(), NewWidth
);
832 auto *LHS
= B
.CreateTruncOrBitCast(Instr
->getOperand(0), TruncTy
,
833 Instr
->getName() + ".lhs.trunc");
834 auto *RHS
= B
.CreateTruncOrBitCast(Instr
->getOperand(1), TruncTy
,
835 Instr
->getName() + ".rhs.trunc");
836 auto *BO
= B
.CreateBinOp(Instr
->getOpcode(), LHS
, RHS
, Instr
->getName());
837 auto *Zext
= B
.CreateZExt(BO
, Instr
->getType(), Instr
->getName() + ".zext");
838 if (auto *BinOp
= dyn_cast
<BinaryOperator
>(BO
))
839 if (BinOp
->getOpcode() == Instruction::UDiv
)
840 BinOp
->setIsExact(Instr
->isExact());
842 Instr
->replaceAllUsesWith(Zext
);
843 Instr
->eraseFromParent();
847 static bool processUDivOrURem(BinaryOperator
*Instr
, LazyValueInfo
*LVI
) {
848 assert(Instr
->getOpcode() == Instruction::UDiv
||
849 Instr
->getOpcode() == Instruction::URem
);
850 if (Instr
->getType()->isVectorTy())
853 ConstantRange XCR
= LVI
->getConstantRangeAtUse(Instr
->getOperandUse(0),
854 /*UndefAllowed*/ false);
855 // Allow undef for RHS, as we can assume it is division by zero UB.
856 ConstantRange YCR
= LVI
->getConstantRangeAtUse(Instr
->getOperandUse(1),
857 /*UndefAllowed*/ true);
858 if (expandUDivOrURem(Instr
, XCR
, YCR
))
861 return narrowUDivOrURem(Instr
, XCR
, YCR
);
864 static bool processSRem(BinaryOperator
*SDI
, const ConstantRange
&LCR
,
865 const ConstantRange
&RCR
, LazyValueInfo
*LVI
) {
866 assert(SDI
->getOpcode() == Instruction::SRem
);
867 assert(!SDI
->getType()->isVectorTy());
869 if (LCR
.abs().icmp(CmpInst::ICMP_ULT
, RCR
.abs())) {
870 SDI
->replaceAllUsesWith(SDI
->getOperand(0));
871 SDI
->eraseFromParent();
879 std::array
<Operand
, 2> Ops
= {{{SDI
->getOperand(0), getDomain(LCR
)},
880 {SDI
->getOperand(1), getDomain(RCR
)}}};
881 if (Ops
[0].D
== Domain::Unknown
|| Ops
[1].D
== Domain::Unknown
)
884 // We know domains of both of the operands!
887 // We need operands to be non-negative, so negate each one that isn't.
888 for (Operand
&Op
: Ops
) {
889 if (Op
.D
== Domain::NonNegative
)
892 BinaryOperator::CreateNeg(Op
.V
, Op
.V
->getName() + ".nonneg", SDI
);
893 BO
->setDebugLoc(SDI
->getDebugLoc());
898 BinaryOperator::CreateURem(Ops
[0].V
, Ops
[1].V
, SDI
->getName(), SDI
);
899 URem
->setDebugLoc(SDI
->getDebugLoc());
903 // If the divident was non-positive, we need to negate the result.
904 if (Ops
[0].D
== Domain::NonPositive
) {
905 Res
= BinaryOperator::CreateNeg(Res
, Res
->getName() + ".neg", SDI
);
906 Res
->setDebugLoc(SDI
->getDebugLoc());
909 SDI
->replaceAllUsesWith(Res
);
910 SDI
->eraseFromParent();
912 // Try to simplify our new urem.
913 processUDivOrURem(URem
, LVI
);
918 /// See if LazyValueInfo's ability to exploit edge conditions or range
919 /// information is sufficient to prove the signs of both operands of this SDiv.
920 /// If this is the case, replace the SDiv with a UDiv. Even for local
921 /// conditions, this can sometimes prove conditions instcombine can't by
922 /// exploiting range information.
923 static bool processSDiv(BinaryOperator
*SDI
, const ConstantRange
&LCR
,
924 const ConstantRange
&RCR
, LazyValueInfo
*LVI
) {
925 assert(SDI
->getOpcode() == Instruction::SDiv
);
926 assert(!SDI
->getType()->isVectorTy());
928 // Check whether the division folds to a constant.
929 ConstantRange DivCR
= LCR
.sdiv(RCR
);
930 if (const APInt
*Elem
= DivCR
.getSingleElement()) {
931 SDI
->replaceAllUsesWith(ConstantInt::get(SDI
->getType(), *Elem
));
932 SDI
->eraseFromParent();
940 std::array
<Operand
, 2> Ops
= {{{SDI
->getOperand(0), getDomain(LCR
)},
941 {SDI
->getOperand(1), getDomain(RCR
)}}};
942 if (Ops
[0].D
== Domain::Unknown
|| Ops
[1].D
== Domain::Unknown
)
945 // We know domains of both of the operands!
948 // We need operands to be non-negative, so negate each one that isn't.
949 for (Operand
&Op
: Ops
) {
950 if (Op
.D
== Domain::NonNegative
)
953 BinaryOperator::CreateNeg(Op
.V
, Op
.V
->getName() + ".nonneg", SDI
);
954 BO
->setDebugLoc(SDI
->getDebugLoc());
959 BinaryOperator::CreateUDiv(Ops
[0].V
, Ops
[1].V
, SDI
->getName(), SDI
);
960 UDiv
->setDebugLoc(SDI
->getDebugLoc());
961 UDiv
->setIsExact(SDI
->isExact());
965 // If the operands had two different domains, we need to negate the result.
966 if (Ops
[0].D
!= Ops
[1].D
) {
967 Res
= BinaryOperator::CreateNeg(Res
, Res
->getName() + ".neg", SDI
);
968 Res
->setDebugLoc(SDI
->getDebugLoc());
971 SDI
->replaceAllUsesWith(Res
);
972 SDI
->eraseFromParent();
974 // Try to simplify our new udiv.
975 processUDivOrURem(UDiv
, LVI
);
980 static bool processSDivOrSRem(BinaryOperator
*Instr
, LazyValueInfo
*LVI
) {
981 assert(Instr
->getOpcode() == Instruction::SDiv
||
982 Instr
->getOpcode() == Instruction::SRem
);
983 if (Instr
->getType()->isVectorTy())
987 LVI
->getConstantRangeAtUse(Instr
->getOperandUse(0), /*AllowUndef*/ false);
988 // Allow undef for RHS, as we can assume it is division by zero UB.
990 LVI
->getConstantRangeAtUse(Instr
->getOperandUse(1), /*AlloweUndef*/ true);
991 if (Instr
->getOpcode() == Instruction::SDiv
)
992 if (processSDiv(Instr
, LCR
, RCR
, LVI
))
995 if (Instr
->getOpcode() == Instruction::SRem
) {
996 if (processSRem(Instr
, LCR
, RCR
, LVI
))
1000 return narrowSDivOrSRem(Instr
, LCR
, RCR
);
1003 static bool processAShr(BinaryOperator
*SDI
, LazyValueInfo
*LVI
) {
1004 if (SDI
->getType()->isVectorTy())
1007 ConstantRange LRange
=
1008 LVI
->getConstantRangeAtUse(SDI
->getOperandUse(0), /*UndefAllowed*/ false);
1009 unsigned OrigWidth
= SDI
->getType()->getIntegerBitWidth();
1010 ConstantRange NegOneOrZero
=
1011 ConstantRange(APInt(OrigWidth
, (uint64_t)-1, true), APInt(OrigWidth
, 1));
1012 if (NegOneOrZero
.contains(LRange
)) {
1013 // ashr of -1 or 0 never changes the value, so drop the whole instruction
1015 SDI
->replaceAllUsesWith(SDI
->getOperand(0));
1016 SDI
->eraseFromParent();
1020 if (!LRange
.isAllNonNegative())
1023 ++NumAShrsConverted
;
1024 auto *BO
= BinaryOperator::CreateLShr(SDI
->getOperand(0), SDI
->getOperand(1),
1027 BO
->setDebugLoc(SDI
->getDebugLoc());
1028 BO
->setIsExact(SDI
->isExact());
1029 SDI
->replaceAllUsesWith(BO
);
1030 SDI
->eraseFromParent();
1035 static bool processSExt(SExtInst
*SDI
, LazyValueInfo
*LVI
) {
1036 if (SDI
->getType()->isVectorTy())
1039 const Use
&Base
= SDI
->getOperandUse(0);
1040 if (!LVI
->getConstantRangeAtUse(Base
, /*UndefAllowed*/ false)
1041 .isAllNonNegative())
1045 auto *ZExt
= CastInst::CreateZExtOrBitCast(Base
, SDI
->getType(), "", SDI
);
1046 ZExt
->takeName(SDI
);
1047 ZExt
->setDebugLoc(SDI
->getDebugLoc());
1049 SDI
->replaceAllUsesWith(ZExt
);
1050 SDI
->eraseFromParent();
1055 static bool processZExt(ZExtInst
*ZExt
, LazyValueInfo
*LVI
) {
1056 if (ZExt
->getType()->isVectorTy())
1059 if (ZExt
->hasNonNeg())
1062 const Use
&Base
= ZExt
->getOperandUse(0);
1063 if (!LVI
->getConstantRangeAtUse(Base
, /*UndefAllowed*/ false)
1064 .isAllNonNegative())
1073 static bool processBinOp(BinaryOperator
*BinOp
, LazyValueInfo
*LVI
) {
1074 using OBO
= OverflowingBinaryOperator
;
1076 if (BinOp
->getType()->isVectorTy())
1079 bool NSW
= BinOp
->hasNoSignedWrap();
1080 bool NUW
= BinOp
->hasNoUnsignedWrap();
1084 Instruction::BinaryOps Opcode
= BinOp
->getOpcode();
1085 Value
*LHS
= BinOp
->getOperand(0);
1086 Value
*RHS
= BinOp
->getOperand(1);
1088 ConstantRange LRange
=
1089 LVI
->getConstantRange(LHS
, BinOp
, /*UndefAllowed*/ false);
1090 ConstantRange RRange
=
1091 LVI
->getConstantRange(RHS
, BinOp
, /*UndefAllowed*/ false);
1093 bool Changed
= false;
1094 bool NewNUW
= false, NewNSW
= false;
1096 ConstantRange NUWRange
= ConstantRange::makeGuaranteedNoWrapRegion(
1097 Opcode
, RRange
, OBO::NoUnsignedWrap
);
1098 NewNUW
= NUWRange
.contains(LRange
);
1102 ConstantRange NSWRange
= ConstantRange::makeGuaranteedNoWrapRegion(
1103 Opcode
, RRange
, OBO::NoSignedWrap
);
1104 NewNSW
= NSWRange
.contains(LRange
);
1108 setDeducedOverflowingFlags(BinOp
, Opcode
, NewNSW
, NewNUW
);
1113 static bool processAnd(BinaryOperator
*BinOp
, LazyValueInfo
*LVI
) {
1114 if (BinOp
->getType()->isVectorTy())
1117 // Pattern match (and lhs, C) where C includes a superset of bits which might
1118 // be set in lhs. This is a common truncation idiom created by instcombine.
1119 const Use
&LHS
= BinOp
->getOperandUse(0);
1120 ConstantInt
*RHS
= dyn_cast
<ConstantInt
>(BinOp
->getOperand(1));
1121 if (!RHS
|| !RHS
->getValue().isMask())
1124 // We can only replace the AND with LHS based on range info if the range does
1125 // not include undef.
1126 ConstantRange LRange
=
1127 LVI
->getConstantRangeAtUse(LHS
, /*UndefAllowed=*/false);
1128 if (!LRange
.getUnsignedMax().ule(RHS
->getValue()))
1131 BinOp
->replaceAllUsesWith(LHS
);
1132 BinOp
->eraseFromParent();
1137 static bool runImpl(Function
&F
, LazyValueInfo
*LVI
, DominatorTree
*DT
,
1138 const SimplifyQuery
&SQ
) {
1139 bool FnChanged
= false;
1140 // Visiting in a pre-order depth-first traversal causes us to simplify early
1141 // blocks before querying later blocks (which require us to analyze early
1142 // blocks). Eagerly simplifying shallow blocks means there is strictly less
1143 // work to do for deep blocks. This also means we don't visit unreachable
1145 for (BasicBlock
*BB
: depth_first(&F
.getEntryBlock())) {
1146 bool BBChanged
= false;
1147 for (Instruction
&II
: llvm::make_early_inc_range(*BB
)) {
1148 switch (II
.getOpcode()) {
1149 case Instruction::Select
:
1150 BBChanged
|= processSelect(cast
<SelectInst
>(&II
), LVI
);
1152 case Instruction::PHI
:
1153 BBChanged
|= processPHI(cast
<PHINode
>(&II
), LVI
, DT
, SQ
);
1155 case Instruction::ICmp
:
1156 case Instruction::FCmp
:
1157 BBChanged
|= processCmp(cast
<CmpInst
>(&II
), LVI
);
1159 case Instruction::Call
:
1160 case Instruction::Invoke
:
1161 BBChanged
|= processCallSite(cast
<CallBase
>(II
), LVI
);
1163 case Instruction::SRem
:
1164 case Instruction::SDiv
:
1165 BBChanged
|= processSDivOrSRem(cast
<BinaryOperator
>(&II
), LVI
);
1167 case Instruction::UDiv
:
1168 case Instruction::URem
:
1169 BBChanged
|= processUDivOrURem(cast
<BinaryOperator
>(&II
), LVI
);
1171 case Instruction::AShr
:
1172 BBChanged
|= processAShr(cast
<BinaryOperator
>(&II
), LVI
);
1174 case Instruction::SExt
:
1175 BBChanged
|= processSExt(cast
<SExtInst
>(&II
), LVI
);
1177 case Instruction::ZExt
:
1178 BBChanged
|= processZExt(cast
<ZExtInst
>(&II
), LVI
);
1180 case Instruction::Add
:
1181 case Instruction::Sub
:
1182 case Instruction::Mul
:
1183 case Instruction::Shl
:
1184 BBChanged
|= processBinOp(cast
<BinaryOperator
>(&II
), LVI
);
1186 case Instruction::And
:
1187 BBChanged
|= processAnd(cast
<BinaryOperator
>(&II
), LVI
);
1192 Instruction
*Term
= BB
->getTerminator();
1193 switch (Term
->getOpcode()) {
1194 case Instruction::Switch
:
1195 BBChanged
|= processSwitch(cast
<SwitchInst
>(Term
), LVI
, DT
);
1197 case Instruction::Ret
: {
1198 auto *RI
= cast
<ReturnInst
>(Term
);
1199 // Try to determine the return value if we can. This is mainly here to
1200 // simplify the writing of unit tests, but also helps to enable IPO by
1201 // constant folding the return values of callees.
1202 auto *RetVal
= RI
->getReturnValue();
1203 if (!RetVal
) break; // handle "ret void"
1204 if (isa
<Constant
>(RetVal
)) break; // nothing to do
1205 if (auto *C
= getConstantAt(RetVal
, RI
, LVI
)) {
1207 RI
->replaceUsesOfWith(RetVal
, C
);
1213 FnChanged
|= BBChanged
;
1220 CorrelatedValuePropagationPass::run(Function
&F
, FunctionAnalysisManager
&AM
) {
1221 LazyValueInfo
*LVI
= &AM
.getResult
<LazyValueAnalysis
>(F
);
1222 DominatorTree
*DT
= &AM
.getResult
<DominatorTreeAnalysis
>(F
);
1224 bool Changed
= runImpl(F
, LVI
, DT
, getBestSimplifyQuery(AM
, F
));
1226 PreservedAnalyses PA
;
1228 PA
= PreservedAnalyses::all();
1230 PA
.preserve
<DominatorTreeAnalysis
>();
1231 PA
.preserve
<LazyValueAnalysis
>();
1234 // Keeping LVI alive is expensive, both because it uses a lot of memory, and
1235 // because invalidating values in LVI is expensive. While CVP does preserve
1236 // LVI, we know that passes after JumpThreading+CVP will not need the result
1237 // of this analysis, so we forcefully discard it early.
1238 PA
.abandon
<LazyValueAnalysis
>();