[llvm] 3306ae1 - [WasmEHPrepare] Don't use IRBuilder for constexpr GEP (#226108)

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 24 04:24:59 PDT 2026


Author: Nikita Popov
Date: 2026-09-24T11:24:52Z
New Revision: 3306ae1c98d695d7d111bd8037380c7d09e818b6

URL: https://github.com/llvm/llvm-project/commit/3306ae1c98d695d7d111bd8037380c7d09e818b6
DIFF: https://github.com/llvm/llvm-project/commit/3306ae1c98d695d7d111bd8037380c7d09e818b6.diff

LOG: [WasmEHPrepare] Don't use IRBuilder for constexpr GEP (#226108)

Do not use an IRBuilder without an insertion point to create
a constant expression get. Directly create the constant expression
instead.

Added: 
    

Modified: 
    llvm/lib/CodeGen/WasmEHPrepare.cpp
    llvm/test/CodeGen/WebAssembly/wasm-eh-prepare.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/WasmEHPrepare.cpp b/llvm/lib/CodeGen/WasmEHPrepare.cpp
index 8e9acc4688c5f..3ac0126c9c9a1 100644
--- a/llvm/lib/CodeGen/WasmEHPrepare.cpp
+++ b/llvm/lib/CodeGen/WasmEHPrepare.cpp
@@ -206,7 +206,8 @@ bool WasmEHPrepareImpl::prepareThrows(Function &F) {
 
 bool WasmEHPrepareImpl::prepareEHPads(Function &F) {
   Module &M = *F.getParent();
-  IRBuilder<> IRB(F.getContext());
+  LLVMContext &Ctx = M.getContext();
+  const DataLayout &DL = M.getDataLayout();
 
   SmallVector<BasicBlock *, 16> CatchPads;
   SmallVector<BasicBlock *, 16> CleanupPads;
@@ -242,10 +243,16 @@ bool WasmEHPrepareImpl::prepareEHPads(Function &F) {
   LPadContextGV->setThreadLocalMode(GlobalValue::GeneralDynamicTLSModel);
 
   LPadIndexField = LPadContextGV;
-  LSDAField = IRB.CreateConstInBoundsGEP2_32(LPadContextTy, LPadContextGV, 0, 1,
-                                             "lsda_gep");
-  SelectorField = IRB.CreateConstInBoundsGEP2_32(LPadContextTy, LPadContextGV,
-                                                 0, 2, "selector_gep");
+  LSDAField =
+      ConstantExpr::getGetElementPtr(DL, LPadContextTy, LPadContextGV,
+                                     {ConstantInt::get(Ctx, APInt(32, 0)),
+                                      ConstantInt::get(Ctx, APInt(32, 1))},
+                                     GEPNoWrapFlags::inBounds());
+  SelectorField =
+      ConstantExpr::getGetElementPtr(DL, LPadContextTy, LPadContextGV,
+                                     {ConstantInt::get(Ctx, APInt(32, 0)),
+                                      ConstantInt::get(Ctx, APInt(32, 2))},
+                                     GEPNoWrapFlags::inBounds());
 
   // wasm.landingpad.index() intrinsic, which is to specify landingpad index
   LPadIndexF =
@@ -264,8 +271,8 @@ bool WasmEHPrepareImpl::prepareEHPads(Function &F) {
   // instruction selection.
   CatchF = Intrinsic::getOrInsertDeclaration(&M, Intrinsic::wasm_catch);
 
-  auto *PersPrototype =
-      FunctionType::get(IRB.getInt32Ty(), {IRB.getPtrTy()}, false);
+  auto *PersPrototype = FunctionType::get(Type::getInt32Ty(Ctx),
+                                          {PointerType::getUnqual(Ctx)}, false);
   PersonalityF =
       M.getOrInsertFunction(getEHPersonalityName(Personality), PersPrototype);
 

diff  --git a/llvm/test/CodeGen/WebAssembly/wasm-eh-prepare.ll b/llvm/test/CodeGen/WebAssembly/wasm-eh-prepare.ll
index 4277bc8ae6692..2eacaed8223f4 100644
--- a/llvm/test/CodeGen/WebAssembly/wasm-eh-prepare.ll
+++ b/llvm/test/CodeGen/WebAssembly/wasm-eh-prepare.ll
@@ -45,9 +45,9 @@ catch.start:                                      ; preds = %catch.dispatch
 ; CHECK-NEXT:   call void @llvm.wasm.landingpad.index(token %[[CATCHPAD]], i32 0)
 ; CHECK-NEXT:   store i32 0, ptr @__wasm_lpad_context
 ; CHECK-NEXT:   %[[LSDA:.*]] = call ptr @llvm.wasm.lsda()
-; CHECK-NEXT:   store ptr %[[LSDA]], ptr getelementptr inbounds ({ i32, ptr, i32 }, ptr @__wasm_lpad_context, i32 0, i32 1)
+; CHECK-NEXT:   store ptr %[[LSDA]], ptr getelementptr inbounds (i8, ptr @__wasm_lpad_context, i32 4)
 ; CHECK-NEXT:   call i32 @__gxx_wasm_personality_v0(ptr %[[EXN]]) {{.*}} [ "funclet"(token %[[CATCHPAD]]) ]
-; CHECK-NEXT:   %[[SELECTOR:.*]] = load i32, ptr getelementptr inbounds ({ i32, ptr, i32 }, ptr @__wasm_lpad_context, i32 0, i32 2)
+; CHECK-NEXT:   %[[SELECTOR:.*]] = load i32, ptr getelementptr inbounds (i8, ptr @__wasm_lpad_context, i32 8)
 ; CHECK:   icmp eq i32 %[[SELECTOR]]
 
 catch:                                            ; preds = %catch.start


        


More information about the llvm-commits mailing list