[llvm] [InstCombine] Convert load from LUT into a select (PR #98339)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 16 12:27:40 PDT 2024


================
@@ -998,6 +998,105 @@ static bool canSimplifyNullLoadOrGEP(LoadInst &LI, Value *Op) {
   return false;
 }
 
+static Value *foldLoadFromIndexedGlobal(LoadInst &LI, IRBuilderBase &Builder) {
+  if (LI.isVolatile())
+    return nullptr;
+
+  auto *GEP = dyn_cast<GetElementPtrInst>(LI.getPointerOperand());
+  if (!GEP)
+    return nullptr;
+
+  auto *GV = dyn_cast<GlobalVariable>(GEP->getPointerOperand());
+  if (!GV || !GV->isConstant() || !GV->hasDefinitiveInitializer())
+    return nullptr;
+
+  Constant *Init = GV->getInitializer();
+  if (!isa<ConstantArray>(Init) && !isa<ConstantDataArray>(Init))
----------------
nikic wrote:

This will prevent the optimization from working on Rust code. In Rust all constants are wrapped in a packed struct.

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


More information about the llvm-commits mailing list