[PATCH] D49276: [InstCombine] Corrections in comments for division transformation

Aaron Puchert via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 12 18:05:19 PDT 2018


aaronpuchert created this revision.
aaronpuchert added reviewers: spatel, majnemer.
Herald added a subscriber: llvm-commits.

The actual code seems to be correct, but the comments were misleading.


Repository:
  rL LLVM

https://reviews.llvm.org/D49276

Files:
  lib/Transforms/InstCombine/InstCombineMulDivRem.cpp


Index: lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
+++ lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
@@ -623,7 +623,7 @@
   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");
@@ -709,15 +709,15 @@
       APInt C1Shifted = APInt::getOneBitSet(
           C1->getBitWidth(), static_cast<unsigned>(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));
         BO->setIsExact(I.isExact());
         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));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49276.155307.patch
Type: text/x-patch
Size: 1517 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180713/e367cb43/attachment.bin>


More information about the llvm-commits mailing list