[llvm] DSE: lift limitation on sizes being non-scalable (PR #110670)

Ramkumar Ramachandra via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 10 03:51:13 PDT 2024


================
@@ -1016,30 +1016,45 @@ struct DSEState {
       return isMaskedStoreOverwrite(KillingI, DeadI, BatchAA);
     }
 
-    const TypeSize KillingSize = KillingLocSize.getValue();
-    const TypeSize DeadSize = DeadLoc.Size.getValue();
-    // Bail on doing Size comparison which depends on AA for now
-    // TODO: Remove AnyScalable once Alias Analysis deal with scalable vectors
-    const bool AnyScalable =
-        DeadSize.isScalable() || KillingLocSize.isScalable();
-
-    if (AnyScalable)
-      return OW_Unknown;
+    APInt KillingSize = APInt(64, KillingLocSize.getValue().getKnownMinValue());
+    APInt DeadSize = APInt(64, DeadLoc.Size.getValue().getKnownMinValue());
+
+    // We can compare lower-range(KillingSize) with upper-range(DeadSize), using
+    // VScale.
+    ConstantRange CR = getVScaleRange(&F, 64);
+    bool OverflowL, OverflowU;
+    if (KillingLocSize.isScalable() && DeadLoc.Size.isScalable()) {
+      APInt LowerRange = CR.getUnsignedMin().umul_ov(KillingSize, OverflowL);
+      APInt UpperRange = CR.getUnsignedMax().umul_ov(DeadSize, OverflowU);
+      if (!OverflowL && !OverflowU) {
+        KillingSize = LowerRange;
+        DeadSize = UpperRange;
+      }
+    } else if (KillingLocSize.isScalable()) {
----------------
artagnon wrote:

I think that would be an error as the lower-range could overflow, while the upper-range doesn't, and vice-versa.

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


More information about the llvm-commits mailing list