From 9d2099cc0368e0ce5d8b16876a52b3a5a8360853 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Sun, 15 Jul 2018 17:06:59 +0000 Subject: [PATCH] [InstCombine] Corrections in comments for division transformation (NFC) The actual code seems to be correct, but the comments were misleading. Patch by Aaron Puchert! Differential Revision: https://reviews.llvm.org/D49276 llvm-svn: 337131 --- llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp index a539f870..d6adbec 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp @@ -628,7 +628,7 @@ static bool multiplyOverflows(const APInt &C1, const APInt &C2, APInt &Product, return Overflow; } -/// True if C2 is a multiple of C1. Quotient contains C2/C1. +/// True if C1 is a multiple of C2. Quotient contains C1/C2. static bool isMultiple(const APInt &C1, const APInt &C2, APInt &Quotient, bool IsSigned) { assert(C1.getBitWidth() == C2.getBitWidth() && "Constant widths not equal"); @@ -714,7 +714,7 @@ Instruction *InstCombiner::commonIDivTransforms(BinaryOperator &I) { APInt C1Shifted = APInt::getOneBitSet( C1->getBitWidth(), static_cast(C1->getLimitedValue())); - // (X << C1) / C2 -> X / (C2 >> C1) if C2 is a multiple of C1. + // (X << C1) / C2 -> X / (C2 >> C1) if C2 is a multiple of 1 << C1. if (isMultiple(*C2, C1Shifted, Quotient, IsSigned)) { auto *BO = BinaryOperator::Create(I.getOpcode(), X, ConstantInt::get(Ty, Quotient)); @@ -722,7 +722,7 @@ Instruction *InstCombiner::commonIDivTransforms(BinaryOperator &I) { return BO; } - // (X << C1) / C2 -> X * (C2 >> C1) if C1 is a multiple of C2. + // (X << C1) / C2 -> X * ((1 << C1) / C2) if 1 << C1 is a multiple of C2. if (isMultiple(C1Shifted, *C2, Quotient, IsSigned)) { auto *Mul = BinaryOperator::Create(Instruction::Mul, X, ConstantInt::get(Ty, Quotient)); -- 2.7.4