[llvm] [Analysis][ValueTracking] Unify most of the tracking between AssumptionCache and DomConditionCache (PR #83161)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 1 00:42:40 PST 2024


================
@@ -61,85 +62,35 @@ findAffectedValues(CallBase *CI, TargetTransformInfo *TTI,
   // Note: This code must be kept in-sync with the code in
   // computeKnownBitsFromAssume in ValueTracking.
 
-  auto AddAffected = [&Affected](Value *V, unsigned Idx =
-                                               AssumptionCache::ExprResultIdx) {
-    if (isa<Argument>(V) || isa<GlobalValue>(V)) {
-      Affected.push_back({V, Idx});
-    } else if (auto *I = dyn_cast<Instruction>(V)) {
-      Affected.push_back({I, Idx});
-
-      // Peek through unary operators to find the source of the condition.
-      Value *Op;
-      if (match(I, m_PtrToInt(m_Value(Op)))) {
-        if (isa<Instruction>(Op) || isa<Argument>(Op))
-          Affected.push_back({Op, Idx});
-      }
-    }
+  auto InsertAffected = [&Affected](Value *V, int Idx) {
+    Affected.push_back({V, Idx < 0 ? AssumptionCache::ExprResultIdx : Idx});
   };
 
   for (unsigned Idx = 0; Idx != CI->getNumOperandBundles(); Idx++) {
     OperandBundleUse Bundle = CI->getOperandBundleAt(Idx);
     if (Bundle.getTagName() == "separate_storage") {
       assert(Bundle.Inputs.size() == 2 &&
              "separate_storage must have two args");
-      AddAffected(getUnderlyingObject(Bundle.Inputs[0]), Idx);
-      AddAffected(getUnderlyingObject(Bundle.Inputs[1]), Idx);
+      addValueAffectedByCondition(getUnderlyingObject(Bundle.Inputs[0]),
+                                  InsertAffected, Idx);
+      addValueAffectedByCondition(getUnderlyingObject(Bundle.Inputs[1]),
+                                  InsertAffected, Idx);
     } else if (Bundle.Inputs.size() > ABA_WasOn &&
                Bundle.getTagName() != IgnoreBundleTag)
-      AddAffected(Bundle.Inputs[ABA_WasOn], Idx);
+      addValueAffectedByCondition(Bundle.Inputs[ABA_WasOn], InsertAffected,
+                                  Idx);
----------------
nikic wrote:

Using the addValueAffectedByCondition helper doesn't really make sense for the operand bundle assumes, as they don't (and shouldn't) have the special ptrtoint logic it deals with. I think that you should handle these separately (just adding V, Idx for them) and then you can also drop the whole index logic from the shared code as well.

https://github.com/llvm/llvm-project/pull/83161


More information about the llvm-commits mailing list