[PATCH] D87342: Allow targets to augment computeKnownBits with their analysis using TargetTransformInfo
Simon Pilgrim via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 5 11:54:07 PDT 2020
RKSimon accepted this revision.
RKSimon added a comment.
This revision is now accepted and ready to land.
Sorry for the delay @qcolombet - I think the sheer size of the patch kept putting me off! But you're right, most of its trivial plumbing. There's a few bits that it'd be great to (pre-)commit separately if possible.
================
Comment at: llvm/include/llvm/Analysis/TargetTransformInfo.h:52
class ProfileSummaryInfo;
+class OptimizationRemarkEmitter;
class SCEV;
----------------
sorting
================
Comment at: llvm/lib/Analysis/ValueTracking.cpp:468
- assert(!Known.hasConflict() && !Known2.hasConflict());
- // Compute a conservative estimate for high known-0 bits.
- unsigned LeadZ = std::max(Known.countMinLeadingZeros() +
- Known2.countMinLeadingZeros(),
- BitWidth) - BitWidth;
- LeadZ = std::min(LeadZ, BitWidth);
-
- // The result of the bottom bits of an integer multiply can be
- // inferred by looking at the bottom bits of both operands and
- // multiplying them together.
- // We can infer at least the minimum number of known trailing bits
- // of both operands. Depending on number of trailing zeros, we can
- // infer more bits, because (a*b) <=> ((a/m) * (b/n)) * (m*n) assuming
- // a and b are divisible by m and n respectively.
- // We then calculate how many of those bits are inferrable and set
- // the output. For example, the i8 mul:
- // a = XXXX1100 (12)
- // b = XXXX1110 (14)
- // We know the bottom 3 bits are zero since the first can be divided by
- // 4 and the second by 2, thus having ((12/4) * (14/2)) * (2*4).
- // Applying the multiplication to the trimmed arguments gets:
- // XX11 (3)
- // X111 (7)
- // -------
- // XX11
- // XX11
- // XX11
- // XX11
- // -------
- // XXXXX01
- // Which allows us to infer the 2 LSBs. Since we're multiplying the result
- // by 8, the bottom 3 bits will be 0, so we can infer a total of 5 bits.
- // The proof for this can be described as:
- // Pre: (C1 >= 0) && (C1 < (1 << C5)) && (C2 >= 0) && (C2 < (1 << C6)) &&
- // (C7 == (1 << (umin(countTrailingZeros(C1), C5) +
- // umin(countTrailingZeros(C2), C6) +
- // umin(C5 - umin(countTrailingZeros(C1), C5),
- // C6 - umin(countTrailingZeros(C2), C6)))) - 1)
- // %aa = shl i8 %a, C5
- // %bb = shl i8 %b, C6
- // %aaa = or i8 %aa, C1
- // %bbb = or i8 %bb, C2
- // %mul = mul i8 %aaa, %bbb
- // %mask = and i8 %mul, C7
- // =>
- // %mask = i8 ((C1*C2)&C7)
- // Where C5, C6 describe the known bits of %a, %b
- // C1, C2 describe the known bottom bits of %a, %b.
- // C7 describes the mask of the known bits of the result.
- APInt Bottom0 = Known.One;
- APInt Bottom1 = Known2.One;
-
- // How many times we'd be able to divide each argument by 2 (shr by 1).
- // This gives us the number of trailing zeros on the multiplication result.
- unsigned TrailBitsKnown0 = (Known.Zero | Known.One).countTrailingOnes();
- unsigned TrailBitsKnown1 = (Known2.Zero | Known2.One).countTrailingOnes();
- unsigned TrailZero0 = Known.countMinTrailingZeros();
- unsigned TrailZero1 = Known2.countMinTrailingZeros();
- unsigned TrailZ = TrailZero0 + TrailZero1;
-
- // Figure out the fewest known-bits operand.
- unsigned SmallestOperand = std::min(TrailBitsKnown0 - TrailZero0,
- TrailBitsKnown1 - TrailZero1);
- unsigned ResultBitsKnown = std::min(SmallestOperand + TrailZ, BitWidth);
-
- APInt BottomKnown = Bottom0.getLoBits(TrailBitsKnown0) *
- Bottom1.getLoBits(TrailBitsKnown1);
-
- Known.resetAll();
- Known.Zero.setHighBits(LeadZ);
- Known.Zero |= (~BottomKnown).getLoBits(ResultBitsKnown);
- Known.One |= BottomKnown.getLoBits(ResultBitsKnown);
+ Known = KnownBits::computeForMul(Known, Known2);
----------------
Pull this out into its own commit
================
Comment at: llvm/unittests/Analysis/ValueTrackingTest.cpp:1127
+ EXPECT_EQ(Known.One.getZExtValue(), 512u | 32u);
+}
+
----------------
These 2 tests above look like they can pre-committed?
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D87342/new/
https://reviews.llvm.org/D87342
More information about the llvm-commits
mailing list