[llvm] [MemCpyOpt] Merge memset and skip unrelated clobber in one scan (PR #90350)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri May 3 04:49:27 PDT 2024
================
@@ -350,157 +434,148 @@ static void combineAAMetadata(Instruction *ReplInst, Instruction *I) {
combineMetadata(ReplInst, I, KnownIDs, true);
}
+// Return the byte value of instruction.
+static Value * isCandidateToMergeIntoMemset(Instruction *I, const DataLayout &DL) {
+ if (auto *SI = dyn_cast<StoreInst>(I)) {
+ Value *StoredVal = SI->getValueOperand();
+
+ // Avoid merging nontemporal stores since the resulting
+ // memcpy/memset would not be able to preserve the nontemporal hint.
+ if (SI->getMetadata(LLVMContext::MD_nontemporal))
+ return nullptr;
+ // Don't convert stores of non-integral pointer types to memsets (which
+ // stores integers).
+ if (DL.isNonIntegralPointerType(StoredVal->getType()->getScalarType()))
+ return nullptr;
+
+ // We can't track ranges involving scalable types.
+ if (DL.getTypeStoreSize(StoredVal->getType()).isScalable())
+ return nullptr;
+
+ return isBytewiseValue(StoredVal, DL);
+ }
+
+ if (auto *MSI = dyn_cast<MemSetInst>(I)) {
+ if (!isa<ConstantInt>(MSI->getLength()))
+ return nullptr;
+
+ return MSI->getValue();
+ }
+
+ return nullptr;
+}
+
+static Value *getWrittenPtr(Instruction *I) {
+ if (auto *SI = dyn_cast<StoreInst>(I))
+ return SI->getPointerOperand();
+ if (auto *MSI = dyn_cast<MemSetInst>(I))
+ return MSI->getDest();
+ static_assert("Only support store and memset");
----------------
nikic wrote:
```suggestion
llvm_unreachable("Only support store and memset");
```
https://github.com/llvm/llvm-project/pull/90350
More information about the llvm-commits
mailing list