[llvm] [WebAssembly][FastISel] Emit signed loads for sext of i8/i16/i32 (PR #182767)

Demetrius Kanios via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 22 23:19:12 PST 2026


================
@@ -1102,6 +1131,16 @@ bool WebAssemblyFastISel::selectSExt(const Instruction *I) {
   Register In = getRegForValue(Op);
   if (In == 0)
     return false;
+
+  MachineInstr *MI = MRI.getUniqueVRegDef(In);
+  if (MI && isSignedExtLoad(MI->getOpcode())) {
+    // The load instruction has already been folded into a signed load
+    // by selectLoad, so we don't need to emit any extension instruction.
+    // Just map the result of this SExt to the signed load register.
+    updateValueMap(I, In);
+    return true;
+  }
+
----------------
QuantumSegfault wrote:

This block shouldn't be necessary? Bottom-up processing in FastISel means that `sext` will be processed before load. And in any case, even if we emit a redundant `sext`, the DCE at the end of the new `tryToFoldLoadIntoMI` should fix it up.

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


More information about the llvm-commits mailing list