From b9aa67bfcfb097d7bd3f21fb94be86bde331c676 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Tue, 16 Aug 2016 21:26:10 +0000 Subject: [PATCH] [InstCombine] fix variable names to match formula comments; NFC llvm-svn: 278855 --- .../Transforms/InstCombine/InstCombineCompares.cpp | 34 +++++++++++----------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 4cbb22a..0e55961 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -2167,35 +2167,35 @@ Instruction *InstCombiner::foldICmpDivConstant(ICmpInst &ICI, Instruction *LHSI, return nullptr; } -Instruction *InstCombiner::foldICmpSubConstant(ICmpInst &ICI, Instruction *LHSI, - const APInt *RHSV) { +/// Fold icmp (sub X, Y), C. +Instruction *InstCombiner::foldICmpSubConstant(ICmpInst &Cmp, Instruction *Sub, + const APInt *C) { // FIXME: This check restricts all folds under here to scalar types. - ConstantInt *RHS = dyn_cast(ICI.getOperand(1)); + ConstantInt *RHS = dyn_cast(Cmp.getOperand(1)); if (!RHS) return nullptr; - ConstantInt *LHSC = dyn_cast(LHSI->getOperand(0)); - if (!LHSC) + ConstantInt *SubC = dyn_cast(Sub->getOperand(0)); + if (!SubC) return nullptr; - const APInt &LHSV = LHSC->getValue(); + const APInt &C2 = SubC->getValue(); - // C1-X (X|(C2-1)) == C1 - // iff C1 & (C2-1) == C2-1 + // C-X (X|(C2-1)) == C + // iff C & (C2-1) == C2-1 // C2 is a power of 2 - if (ICI.getPredicate() == ICmpInst::ICMP_ULT && LHSI->hasOneUse() && - RHSV->isPowerOf2() && (LHSV & (*RHSV - 1)) == (*RHSV - 1)) + if (Cmp.getPredicate() == ICmpInst::ICMP_ULT && Sub->hasOneUse() && + C->isPowerOf2() && (C2 & (*C - 1)) == (*C - 1)) return new ICmpInst(ICmpInst::ICMP_EQ, - Builder->CreateOr(LHSI->getOperand(1), *RHSV - 1), - LHSC); + Builder->CreateOr(Sub->getOperand(1), *C - 1), SubC); - // C1-X >u C2 -> (X|C2) != C1 - // iff C1 & C2 == C2 + // C-X >u C2 -> (X|C2) != C + // iff C & C2 == C2 // C2+1 is a power of 2 - if (ICI.getPredicate() == ICmpInst::ICMP_UGT && LHSI->hasOneUse() && - (*RHSV + 1).isPowerOf2() && (LHSV & *RHSV) == *RHSV) + if (Cmp.getPredicate() == ICmpInst::ICMP_UGT && Sub->hasOneUse() && + (*C + 1).isPowerOf2() && (C2 & *C) == *C) return new ICmpInst(ICmpInst::ICMP_NE, - Builder->CreateOr(LHSI->getOperand(1), *RHSV), LHSC); + Builder->CreateOr(Sub->getOperand(1), *C), SubC); return nullptr; } -- 2.7.4