[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:13 PST 2026
================
@@ -1267,6 +1306,61 @@ bool WebAssemblyFastISel::selectBitCast(const Instruction *I) {
return true;
}
+static unsigned getSExtLoadOpcode(unsigned Opc, bool A64) {
+ switch (Opc) {
+ default:
+ return false;
+ case WebAssembly::I32_EXTEND8_S_I32:
+ Opc = A64 ? WebAssembly::LOAD8_S_I32_A64 : WebAssembly::LOAD8_S_I32_A32;
+ break;
+ case WebAssembly::I32_EXTEND16_S_I32:
+ Opc = A64 ? WebAssembly::LOAD16_S_I32_A64 : WebAssembly::LOAD16_S_I32_A32;
+ break;
+ case WebAssembly::I64_EXTEND8_S_I64:
+ Opc = A64 ? WebAssembly::LOAD8_S_I64_A64 : WebAssembly::LOAD8_S_I64_A32;
+ break;
+ case WebAssembly::I64_EXTEND16_S_I64:
+ Opc = A64 ? WebAssembly::LOAD16_S_I64_A64 : WebAssembly::LOAD16_S_I64_A32;
+ break;
+ case WebAssembly::I64_EXTEND32_S_I64:
+ case WebAssembly::I64_EXTEND_S_I32:
+ Opc = A64 ? WebAssembly::LOAD32_S_I64_A64 : WebAssembly::LOAD32_S_I64_A32;
+ break;
+ }
+
+ return Opc;
+}
+
+bool WebAssemblyFastISel::WebAssemblyEmitLoad(unsigned Opc, Register &ResultReg,
+ Address &Addr,
+ MachineMemOperand *MMO) {
+ MachineInstrBuilder MIB =
+ BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD, TII.get(Opc), ResultReg);
+ addLoadStoreOperands(Addr, MIB, MMO);
+ return true;
+}
+
+bool WebAssemblyFastISel::tryToFoldLoadIntoMI(MachineInstr *MI, unsigned OpNo,
+ const LoadInst *LI) {
+ bool A64 = Subtarget->hasAddr64();
+ unsigned TargetOpc;
+ if (!(TargetOpc = getSExtLoadOpcode(MI->getOpcode(), A64)))
----------------
QuantumSegfault wrote:
Doesn't _necessarily_ need to be addressed for this PR, but what about the folding of appropriate shl, ashr sequences?
Also, what will this look like once folding of zext is introduced? Does it make sense to just tackle that right away as well?
https://github.com/llvm/llvm-project/pull/182767
More information about the llvm-commits
mailing list