[llvm] [CHERI] Refine LoopIdiomRecognize handling of non-integral pointers. (PR #189402)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 6 12:22:17 PDT 2026


================
@@ -471,11 +471,15 @@ LoopIdiomRecognize::isLegalStore(StoreInst *SI) {
   Value *StoredVal = SI->getValueOperand();
   Value *StorePtr = SI->getPointerOperand();
 
-  // Don't convert stores of non-integral pointer types to memsets (which stores
-  // integers).
-  if (DL->isNonIntegralPointerType(StoredVal->getType()->getScalarType()))
+  if (DL->hasUnstableRepresentation(StoredVal->getType()->getScalarType()))
     return LegalStoreKind::None;
 
+  // Only convert stores of other non-integral pointer types to memsets (which
+  // stores integers) when they are null pointers, which we assume are 0.
----------------
nikic wrote:

I think the justification could be a bit clearer here, as the assumption about the value being 0 is a general one that is not specific to pointers with external state.

I think what we should be mentioning here is that:

 * For memcpy, we specify that memcpy must preserve the external state. (This is part of LangRef.)
 * For memset of zero in particular, we assume that the external state gets set to the same value as a null pointer store. There is really no a priori reason to assume that this is the case, it just happens to be true for CHERI, which is the only user of pointers with external state. Possibly we should just make that an explicit constraint in LangRef as well.

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


More information about the llvm-commits mailing list