[llvm] [SROA] Optimize reloaded values in allocas that escape into readonly nocapture calls. (PR #116645)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 28 02:58:09 PST 2024


================
@@ -5454,6 +5475,79 @@ void SROA::clobberUse(Use &U) {
     }
 }
 
+/// A basic LoadAndStorePromoter that does not remove store nodes.
+class BasicLoadAndStorePromoter : public LoadAndStorePromoter {
+public:
+  BasicLoadAndStorePromoter(ArrayRef<const Instruction *> Insts, SSAUpdater &S,
+                            Type *ZeroType)
+      : LoadAndStorePromoter(Insts, S), ZeroType(ZeroType) {}
+  bool shouldDelete(Instruction *I) const override {
+    return !isa<StoreInst>(I) && !isa<AllocaInst>(I);
+  }
+
+  Value *getValueToUseForAlloca(Instruction *I) const override {
+    return Constant::getNullValue(ZeroType);
----------------
nikic wrote:

```suggestion
    return UndefValue::get(ZeroType);
```

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


More information about the llvm-commits mailing list