File tree Expand file tree Collapse file tree 1 file changed +9
-0
lines changed
llvm/lib/Transforms/Utils Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -314,16 +314,25 @@ static Value *simplifyInstruction(SCCPSolver &Solver,
314314
315315 if (auto CR = MatchTwoInstructionExactRangeCheck ()) {
316316 ConstantRange LRange = GetRange (X);
317+ // Early exit if we know nothing about X.
317318 if (LRange.isFullSet ())
318319 return nullptr ;
320+ // We are allowed to refine the comparison to either true or false for out
321+ // of range inputs. Here we refine the comparison to true, i.e. we relax
322+ // the range check.
319323 auto NewCR = CR->exactUnionWith (LRange.inverse ());
324+ // TODO: Check if we can narrow the range check to an equality test.
325+ // E.g, for X in [0, 4), X - 3 u< 2 -> X == 3
320326 if (!NewCR)
321327 return nullptr ;
322328 // Avoid transforming cases which do not relax the range.
329+ // Without this we may revert the transform
330+ // (X - C) < Pow2 -> (X & -Pow2) == C.
323331 if (NewCR.value () == *CR)
324332 return nullptr ;
325333 ICmpInst::Predicate Pred;
326334 APInt RHS;
335+ // Check if we can represent NewCR as an icmp predicate.
327336 if (NewCR->getEquivalentICmp (Pred, RHS)) {
328337 IRBuilder<NoFolder> Builder (&Inst);
329338 Value *NewICmp =
You can’t perform that action at this time.
0 commit comments