[llvm] [NVPTX] instcombine known pointer AS checks. (PR #112964)

Artem Belevich via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 28 12:14:52 PDT 2024


================
@@ -6365,6 +6367,32 @@ static Value *simplifyUnaryIntrinsic(Function *F, Value *Op0,
 
     break;
   }
+  case Intrinsic::nvvm_isspacep_global:
+  case Intrinsic::nvvm_isspacep_local:
+  case Intrinsic::nvvm_isspacep_shared:
+  case Intrinsic::nvvm_isspacep_const: {
+    auto *Ty = F->getReturnType();
+    unsigned AS = Op0->getType()->getPointerAddressSpace();
+    if (AS == NVPTXAS::ADDRESS_SPACE_GENERIC) {
+      if (auto *ASC = dyn_cast<AddrSpaceCastInst>(Op0))
+        AS = ASC->getSrcAddressSpace();
+      else if (auto *ASCO = dyn_cast<AddrSpaceCastOperator>(Op0))
+        AS = ASCO->getOperand(0)->getType()->getPointerAddressSpace();
+    }
----------------
Artem-B wrote:

Ooh. This is convenient. Thanks for pointing it out. 

Coincidentally, the current tests in the patch didn't actually test handling of ASC instruction, as instcombine collapsed ASC(constant) into an ASC operator before we've got to handle the intrinsics. I'll update the code and the tests.

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


More information about the llvm-commits mailing list