[llvm] [ValueTracking] Allow tracking values through Integral AddrSpaceCasts (PR #70483)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 7 03:24:56 PST 2023


================
@@ -1775,6 +1775,34 @@ static void computeKnownBitsFromOperator(const Operator *I,
                                   Depth + 1))
       computeKnownBits(I->getOperand(0), Known, Depth + 1, Q);
     break;
+  case Instruction::AddrSpaceCast: {
+    auto ASC = cast<AddrSpaceCastOperator>(I);
+    unsigned SrcAS = ASC->getSrcAddressSpace();
+    unsigned DestAS = ASC->getDestAddressSpace();
+
+    auto DL = Q.DL;
+    if (DL.isNonIntegralAddressSpace(SrcAS) ||
+        DL.isNonIntegralAddressSpace(DestAS))
+      break;
+
+    auto SrcSize = DL.getPointerSizeInBits(SrcAS);
+    auto DstSize = DL.getPointerSizeInBits(DestAS);
+
+    if (DstSize > SrcSize) {
+      Known2 = Known;
+      Known2 = Known2.clearLowBits(SrcSize);
+      Known = Known.trunc(SrcSize);
----------------
nikic wrote:

I have no idea what you're even trying to do here. `Known` is an out variable that will have unknown bits initially. Assigning `Known` before a computeKnownBits() call doesn't make sense. What you probably want to do is just declare a new KnownBits variable with the correct bit width.

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


More information about the llvm-commits mailing list