[PATCH] D109288: [AggresiveInstCombine] Add wrapper calls for `KnownBits` computing

Anton Afanasyev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 5 06:44:50 PDT 2021


anton-afanasyev created this revision.
anton-afanasyev added reviewers: spatel, lebedev.ri, RKSimon.
Herald added subscribers: foad, hiraditya.
anton-afanasyev requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Precommit before `AssumptionCache` adding: reviews.llvm.org/D109141 <https://reviews.llvm.org/D109141>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D109288

Files:
  llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombineInternal.h
  llvm/lib/Transforms/AggressiveInstCombine/TruncInstCombine.cpp


Index: llvm/lib/Transforms/AggressiveInstCombine/TruncInstCombine.cpp
===================================================================
--- llvm/lib/Transforms/AggressiveInstCombine/TruncInstCombine.cpp
+++ llvm/lib/Transforms/AggressiveInstCombine/TruncInstCombine.cpp
@@ -288,19 +288,19 @@
   for (auto &Itr : InstInfoMap) {
     Instruction *I = Itr.first;
     if (I->isShift()) {
-      KnownBits KnownRHS = computeKnownBits(I->getOperand(1), DL);
+      KnownBits KnownRHS = computeKnownBits(I->getOperand(1));
       unsigned MinBitWidth = KnownRHS.getMaxValue()
                                  .uadd_sat(APInt(OrigBitWidth, 1))
                                  .getLimitedValue(OrigBitWidth);
       if (MinBitWidth == OrigBitWidth)
         return nullptr;
       if (I->getOpcode() == Instruction::LShr) {
-        KnownBits KnownLHS = computeKnownBits(I->getOperand(0), DL);
+        KnownBits KnownLHS = computeKnownBits(I->getOperand(0));
         MinBitWidth =
             std::max(MinBitWidth, KnownLHS.getMaxValue().getActiveBits());
       }
       if (I->getOpcode() == Instruction::AShr) {
-        unsigned NumSignBits = ComputeNumSignBits(I->getOperand(0), DL);
+        unsigned NumSignBits = ComputeNumSignBits(I->getOperand(0));
         MinBitWidth = std::max(MinBitWidth, OrigBitWidth - NumSignBits + 1);
       }
       if (MinBitWidth >= OrigBitWidth)
Index: llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombineInternal.h
===================================================================
--- llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombineInternal.h
+++ llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombineInternal.h
@@ -17,6 +17,8 @@
 
 #include "llvm/ADT/MapVector.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/Analysis/ValueTracking.h"
+#include "llvm/Support/KnownBits.h"
 
 using namespace llvm;
 
@@ -104,6 +106,18 @@
   ///         to be reduced.
   Type *getBestTruncatedType();
 
+  KnownBits computeKnownBits(const Value *V) const {
+    return llvm::computeKnownBits(V, DL, /*Depth=*/0, /*AC=*/nullptr,
+                                  /*CtxI=*/cast<Instruction>(CurrentTruncInst),
+                                  &DT);
+  }
+
+  unsigned ComputeNumSignBits(const Value *V) const {
+    return llvm::ComputeNumSignBits(
+        V, DL, /*Depth=*/0, /*AC=*/nullptr,
+        /*CtxI=*/cast<Instruction>(CurrentTruncInst), &DT);
+  }
+
   /// Given a \p V value and a \p SclTy scalar type return the generated reduced
   /// value of \p V based on the type \p SclTy.
   ///


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109288.370794.patch
Type: text/x-patch
Size: 2569 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210905/00e48c25/attachment.bin>


More information about the llvm-commits mailing list