[PATCH] D48828: [InstSimplify] fold extracting from std::pair

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 16 07:32:17 PDT 2018


lebedev.ri added inline comments.


================
Comment at: lib/Analysis/InstructionSimplify.cpp:1274-1278
+  // If the operation is extracting a member from std::pair,
+  // we can bypass make_pair.
+  // def make_pair(X,Y) := (X << ShiftCnt) | Y
+  //     assuming sizeof(X) + ShiftCnt <= OpWidth and sizeof(Y) <= ShiftCnt
+  // make_pair(X,Y).first = ((X << ShiftCnt) | Y) >> ShiftCnt -> X
----------------
inouehrs wrote:
> lebedev.ri wrote:
> > I think this shouldn't talk about C++ here. Just talk about IR.
> > ```
> > // Given  Op0 l>> Op1.
> > // If Op1 is a constant, and Op0 is  (X nuw<< Op1) | Y
> > // If Y l>> Op1 == 0. we can extract `X` without extra instructions.
> > ```
> Is this better? I mention std::pair as an example.
  There are LLVM IR structures https://llvm.org/docs/LangRef.html#structure-types
  Is the comment talking about them? Huh, why does it operate on integers then?
And other thoughts the readers will have later on. I'd concentrate on IR.


================
Comment at: lib/Analysis/InstructionSimplify.cpp:1286-1290
+    KnownBits YKnown = computeKnownBits(Y, Q.DL, 0, Q.AC, Q.CxtI, Q.DT);
+    unsigned ShiftCnt = cast<ConstantInt>(Op1)->getZExtValue();
+    unsigned Width = Op0->getType()->getScalarSizeInBits();
+    unsigned WidthY = Width - YKnown.countMinLeadingZeros();
+    if (WidthY <= ShiftCnt)
----------------
Can you add a comment explaining what/how this does?
(Checks that `(%x << %op1) | %y` does not touch any bits in `%x`)


================
Comment at: lib/Analysis/InstructionSimplify.cpp:1289
+    unsigned Width = Op0->getType()->getScalarSizeInBits();
+    unsigned WidthY = Width - YKnown.countMinLeadingZeros();
+    if (WidthY <= ShiftCnt)
----------------
But this isn't the width of `Y`, that's `Y->getType()->getScalarSizeInBits()`.
Maybe //effective// width of `Y`.


================
Comment at: test/Transforms/InstSimplify/pair.ll:1
+; RUN: opt < %s -instsimplify -S | FileCheck %s
+
----------------
Use `./utils/update_test_checks.py` please.


https://reviews.llvm.org/D48828





More information about the llvm-commits mailing list