1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 12:41:49 +01:00

[InstCombine] fix comments to match code; NFC

This blob was written before match() existed, so it
could probably be reduced significantly.

But I suspect it isn't well tested, so tests would have
to be added to reduce risk from logic changes.

llvm-svn: 371978
This commit is contained in:
Sanjay Patel 2019-09-16 12:12:05 +00:00
parent e650a1bca0
commit f3b2d06155

View File

@ -3684,17 +3684,19 @@ Instruction *InstCombiner::foldICmpBinOp(ICmpInst &I) {
D = BO1->getOperand(1); D = BO1->getOperand(1);
} }
// icmp (X+Y), X -> icmp Y, 0 for equalities or if there is no overflow. // icmp (A+B), A -> icmp B, 0 for equalities or if there is no overflow.
// icmp (A+B), B -> icmp A, 0 for equalities or if there is no overflow.
if ((A == Op1 || B == Op1) && NoOp0WrapProblem) if ((A == Op1 || B == Op1) && NoOp0WrapProblem)
return new ICmpInst(Pred, A == Op1 ? B : A, return new ICmpInst(Pred, A == Op1 ? B : A,
Constant::getNullValue(Op1->getType())); Constant::getNullValue(Op1->getType()));
// icmp X, (X+Y) -> icmp 0, Y for equalities or if there is no overflow. // icmp C, (C+D) -> icmp 0, D for equalities or if there is no overflow.
// icmp D, (C+D) -> icmp 0, C for equalities or if there is no overflow.
if ((C == Op0 || D == Op0) && NoOp1WrapProblem) if ((C == Op0 || D == Op0) && NoOp1WrapProblem)
return new ICmpInst(Pred, Constant::getNullValue(Op0->getType()), return new ICmpInst(Pred, Constant::getNullValue(Op0->getType()),
C == Op0 ? D : C); C == Op0 ? D : C);
// icmp (X+Y), (X+Z) -> icmp Y, Z for equalities or if there is no overflow. // icmp (A+B), (A+D) -> icmp B, D for equalities or if there is no overflow.
// TODO: The one-use checks should not be necessary. // TODO: The one-use checks should not be necessary.
if (A && C && (A == C || A == D || B == C || B == D) && NoOp0WrapProblem && if (A && C && (A == C || A == D || B == C || B == D) && NoOp0WrapProblem &&
NoOp1WrapProblem && NoOp1WrapProblem &&
@ -3723,39 +3725,39 @@ Instruction *InstCombiner::foldICmpBinOp(ICmpInst &I) {
return new ICmpInst(Pred, Y, Z); return new ICmpInst(Pred, Y, Z);
} }
// icmp slt (X + -1), Y -> icmp sle X, Y // icmp slt (A + -1), Op1 -> icmp sle A, Op1
if (A && NoOp0WrapProblem && Pred == CmpInst::ICMP_SLT && if (A && NoOp0WrapProblem && Pred == CmpInst::ICMP_SLT &&
match(B, m_AllOnes())) match(B, m_AllOnes()))
return new ICmpInst(CmpInst::ICMP_SLE, A, Op1); return new ICmpInst(CmpInst::ICMP_SLE, A, Op1);
// icmp sge (X + -1), Y -> icmp sgt X, Y // icmp sge (A + -1), Op1 -> icmp sgt A, Op1
if (A && NoOp0WrapProblem && Pred == CmpInst::ICMP_SGE && if (A && NoOp0WrapProblem && Pred == CmpInst::ICMP_SGE &&
match(B, m_AllOnes())) match(B, m_AllOnes()))
return new ICmpInst(CmpInst::ICMP_SGT, A, Op1); return new ICmpInst(CmpInst::ICMP_SGT, A, Op1);
// icmp sle (X + 1), Y -> icmp slt X, Y // icmp sle (A + 1), Op1 -> icmp slt A, Op1
if (A && NoOp0WrapProblem && Pred == CmpInst::ICMP_SLE && match(B, m_One())) if (A && NoOp0WrapProblem && Pred == CmpInst::ICMP_SLE && match(B, m_One()))
return new ICmpInst(CmpInst::ICMP_SLT, A, Op1); return new ICmpInst(CmpInst::ICMP_SLT, A, Op1);
// icmp sgt (X + 1), Y -> icmp sge X, Y // icmp sgt (A + 1), Op1 -> icmp sge A, Op1
if (A && NoOp0WrapProblem && Pred == CmpInst::ICMP_SGT && match(B, m_One())) if (A && NoOp0WrapProblem && Pred == CmpInst::ICMP_SGT && match(B, m_One()))
return new ICmpInst(CmpInst::ICMP_SGE, A, Op1); return new ICmpInst(CmpInst::ICMP_SGE, A, Op1);
// icmp sgt X, (Y + -1) -> icmp sge X, Y // icmp sgt Op0, (C + -1) -> icmp sge Op0, C
if (C && NoOp1WrapProblem && Pred == CmpInst::ICMP_SGT && if (C && NoOp1WrapProblem && Pred == CmpInst::ICMP_SGT &&
match(D, m_AllOnes())) match(D, m_AllOnes()))
return new ICmpInst(CmpInst::ICMP_SGE, Op0, C); return new ICmpInst(CmpInst::ICMP_SGE, Op0, C);
// icmp sle X, (Y + -1) -> icmp slt X, Y // icmp sle Op0, (C + -1) -> icmp slt Op0, C
if (C && NoOp1WrapProblem && Pred == CmpInst::ICMP_SLE && if (C && NoOp1WrapProblem && Pred == CmpInst::ICMP_SLE &&
match(D, m_AllOnes())) match(D, m_AllOnes()))
return new ICmpInst(CmpInst::ICMP_SLT, Op0, C); return new ICmpInst(CmpInst::ICMP_SLT, Op0, C);
// icmp sge X, (Y + 1) -> icmp sgt X, Y // icmp sge Op0, (C + 1) -> icmp sgt Op0, C
if (C && NoOp1WrapProblem && Pred == CmpInst::ICMP_SGE && match(D, m_One())) if (C && NoOp1WrapProblem && Pred == CmpInst::ICMP_SGE && match(D, m_One()))
return new ICmpInst(CmpInst::ICMP_SGT, Op0, C); return new ICmpInst(CmpInst::ICMP_SGT, Op0, C);
// icmp slt X, (Y + 1) -> icmp sle X, Y // icmp slt Op0, (C + 1) -> icmp sle Op0, C
if (C && NoOp1WrapProblem && Pred == CmpInst::ICMP_SLT && match(D, m_One())) if (C && NoOp1WrapProblem && Pred == CmpInst::ICMP_SLT && match(D, m_One()))
return new ICmpInst(CmpInst::ICMP_SLE, Op0, C); return new ICmpInst(CmpInst::ICMP_SLE, Op0, C);
@ -3763,33 +3765,33 @@ Instruction *InstCombiner::foldICmpBinOp(ICmpInst &I) {
// canonicalization from (X -nuw 1) to (X + -1) means that the combinations // canonicalization from (X -nuw 1) to (X + -1) means that the combinations
// wouldn't happen even if they were implemented. // wouldn't happen even if they were implemented.
// //
// icmp ult (X - 1), Y -> icmp ule X, Y // icmp ult (A - 1), Op1 -> icmp ule A, Op1
// icmp uge (X - 1), Y -> icmp ugt X, Y // icmp uge (A - 1), Op1 -> icmp ugt A, Op1
// icmp ugt X, (Y - 1) -> icmp uge X, Y // icmp ugt Op0, (C - 1) -> icmp uge Op0, C
// icmp ule X, (Y - 1) -> icmp ult X, Y // icmp ule Op0, (C - 1) -> icmp ult Op0, C
// icmp ule (X + 1), Y -> icmp ult X, Y // icmp ule (A + 1), Op0 -> icmp ult A, Op1
if (A && NoOp0WrapProblem && Pred == CmpInst::ICMP_ULE && match(B, m_One())) if (A && NoOp0WrapProblem && Pred == CmpInst::ICMP_ULE && match(B, m_One()))
return new ICmpInst(CmpInst::ICMP_ULT, A, Op1); return new ICmpInst(CmpInst::ICMP_ULT, A, Op1);
// icmp ugt (X + 1), Y -> icmp uge X, Y // icmp ugt (A + 1), Op0 -> icmp uge A, Op1
if (A && NoOp0WrapProblem && Pred == CmpInst::ICMP_UGT && match(B, m_One())) if (A && NoOp0WrapProblem && Pred == CmpInst::ICMP_UGT && match(B, m_One()))
return new ICmpInst(CmpInst::ICMP_UGE, A, Op1); return new ICmpInst(CmpInst::ICMP_UGE, A, Op1);
// icmp uge X, (Y + 1) -> icmp ugt X, Y // icmp uge Op0, (C + 1) -> icmp ugt Op0, C
if (C && NoOp1WrapProblem && Pred == CmpInst::ICMP_UGE && match(D, m_One())) if (C && NoOp1WrapProblem && Pred == CmpInst::ICMP_UGE && match(D, m_One()))
return new ICmpInst(CmpInst::ICMP_UGT, Op0, C); return new ICmpInst(CmpInst::ICMP_UGT, Op0, C);
// icmp ult X, (Y + 1) -> icmp ule X, Y // icmp ult Op0, (C + 1) -> icmp ule Op0, C
if (C && NoOp1WrapProblem && Pred == CmpInst::ICMP_ULT && match(D, m_One())) if (C && NoOp1WrapProblem && Pred == CmpInst::ICMP_ULT && match(D, m_One()))
return new ICmpInst(CmpInst::ICMP_ULE, Op0, C); return new ICmpInst(CmpInst::ICMP_ULE, Op0, C);
// if C1 has greater magnitude than C2: // if C1 has greater magnitude than C2:
// icmp (X + C1), (Y + C2) -> icmp (X + C3), Y // icmp (A + C1), (C + C2) -> icmp (A + C3), C
// s.t. C3 = C1 - C2 // s.t. C3 = C1 - C2
// //
// if C2 has greater magnitude than C1: // if C2 has greater magnitude than C1:
// icmp (X + C1), (Y + C2) -> icmp X, (Y + C3) // icmp (A + C1), (C + C2) -> icmp A, (C + C3)
// s.t. C3 = C2 - C1 // s.t. C3 = C2 - C1
if (A && C && NoOp0WrapProblem && NoOp1WrapProblem && if (A && C && NoOp0WrapProblem && NoOp1WrapProblem &&
(BO0->hasOneUse() || BO1->hasOneUse()) && !I.isUnsigned()) (BO0->hasOneUse() || BO1->hasOneUse()) && !I.isUnsigned())
@ -3827,10 +3829,10 @@ Instruction *InstCombiner::foldICmpBinOp(ICmpInst &I) {
D = BO1->getOperand(1); D = BO1->getOperand(1);
} }
// icmp (X-Y), X -> icmp 0, Y for equalities or if there is no overflow. // icmp (A-B), A -> icmp 0, B for equalities or if there is no overflow.
if (A == Op1 && NoOp0WrapProblem) if (A == Op1 && NoOp0WrapProblem)
return new ICmpInst(Pred, Constant::getNullValue(Op1->getType()), B); return new ICmpInst(Pred, Constant::getNullValue(Op1->getType()), B);
// icmp X, (X-Y) -> icmp Y, 0 for equalities or if there is no overflow. // icmp C, (C-D) -> icmp D, 0 for equalities or if there is no overflow.
if (C == Op0 && NoOp1WrapProblem) if (C == Op0 && NoOp1WrapProblem)
return new ICmpInst(Pred, D, Constant::getNullValue(Op0->getType())); return new ICmpInst(Pred, D, Constant::getNullValue(Op0->getType()));
@ -3842,11 +3844,11 @@ Instruction *InstCombiner::foldICmpBinOp(ICmpInst &I) {
if (C == Op0 && (Pred == ICmpInst::ICMP_ULT || Pred == ICmpInst::ICMP_UGE)) if (C == Op0 && (Pred == ICmpInst::ICMP_ULT || Pred == ICmpInst::ICMP_UGE))
return new ICmpInst(Pred, C, D); return new ICmpInst(Pred, C, D);
// icmp (Y-X), (Z-X) -> icmp Y, Z for equalities or if there is no overflow. // icmp (A-B), (C-B) -> icmp A, C for equalities or if there is no overflow.
if (B && D && B == D && NoOp0WrapProblem && NoOp1WrapProblem) if (B && D && B == D && NoOp0WrapProblem && NoOp1WrapProblem)
return new ICmpInst(Pred, A, C); return new ICmpInst(Pred, A, C);
// icmp (X-Y), (X-Z) -> icmp Z, Y for equalities or if there is no overflow. // icmp (A-B), (A-D) -> icmp D, B for equalities or if there is no overflow.
// TODO: The one-use checks should not be necessary. // TODO: The one-use checks should not be necessary.
if (A && C && A == C && NoOp0WrapProblem && NoOp1WrapProblem && if (A && C && A == C && NoOp0WrapProblem && NoOp1WrapProblem &&
// Try not to increase register pressure. // Try not to increase register pressure.