Index: lib/Target/WebAssembly/WebAssemblyInstrAtomics.td =================================================================== --- lib/Target/WebAssembly/WebAssemblyInstrAtomics.td +++ lib/Target/WebAssembly/WebAssemblyInstrAtomics.td @@ -18,16 +18,17 @@ let Defs = [ARGUMENTS] in { // TODO: add the rest of the atomic loads -// TODO: factor out 0xfe atomic prefix? -def ATOMIC_LOAD_I32 : ATOMIC_I<(outs I32:$dst), - (ins P2Align:$p2align, offset32_op:$off, I32:$addr), - [], "i32.atomic.load\t$dst, ${off}(${addr})${p2align}", - 0xfe10>; +def ATOMIC_LOAD_I32 : CLoadI32<"i32.atomic.load", 0xfe10>; +def ATOMIC_LOAD_I64 : CLoadI64<"i64.atomic.load", 0xfe11>; } // Defs = [ARGUMENTS] // Select loads with no constant offset. let Predicates = [HasAtomics] in { -def : Pat<(i32 (atomic_load I32:$addr)), (ATOMIC_LOAD_I32 0, 0, $addr)>; +class ALoadPatNoOffset : + Pat<(ty (node I32:$addr)), (inst 0, 0, $addr)>; +def : ALoadPatNoOffset; +def : ALoadPatNoOffset; + } //===----------------------------------------------------------------------===// Index: lib/Target/WebAssembly/WebAssemblyInstrMemory.td =================================================================== --- lib/Target/WebAssembly/WebAssemblyInstrMemory.td +++ lib/Target/WebAssembly/WebAssemblyInstrMemory.td @@ -55,15 +55,22 @@ let Defs = [ARGUMENTS] in { +// Classes to define both atomic and non-atomic integer loads +class CLoadI32 : + I<(outs I32:$dst), + (ins P2Align:$p2align, offset32_op:$off, I32:$addr), + [], !strconcat(Name, "\t$dst, ${off}(${addr})${p2align}"), Opcode>; + +class CLoadI64 : + I<(outs I64:$dst), + (ins P2Align:$p2align, offset32_op:$off, I32:$addr), + [], !strconcat(Name, "\t$dst, ${off}(${addr})${p2align}"), Opcode>; + // Basic load. // FIXME: When we can break syntax compatibility, reorder the fields in the // asmstrings to match the binary encoding. -def LOAD_I32 : I<(outs I32:$dst), - (ins P2Align:$p2align, offset32_op:$off, I32:$addr), - [], "i32.load\t$dst, ${off}(${addr})${p2align}", 0x28>; -def LOAD_I64 : I<(outs I64:$dst), - (ins P2Align:$p2align, offset32_op:$off, I32:$addr), - [], "i64.load\t$dst, ${off}(${addr})${p2align}", 0x29>; +def LOAD_I32 : CLoadI32<"i32.load", 0x28>; +def LOAD_I64 : CLoadI64<"i64.load", 0x29>; def LOAD_F32 : I<(outs F32:$dst), (ins P2Align:$p2align, offset32_op:$off, I32:$addr), [], "f32.load\t$dst, ${off}(${addr})${p2align}", 0x2a>; @@ -74,70 +81,74 @@ } // Defs = [ARGUMENTS] // Select loads with no constant offset. -def : Pat<(i32 (load I32:$addr)), (LOAD_I32 0, 0, $addr)>; -def : Pat<(i64 (load I32:$addr)), (LOAD_I64 0, 0, $addr)>; -def : Pat<(f32 (load I32:$addr)), (LOAD_F32 0, 0, $addr)>; -def : Pat<(f64 (load I32:$addr)), (LOAD_F64 0, 0, $addr)>; +class LoadPatNoOffset : + Pat<(ty (node I32:$addr)), (inst 0, 0, $addr)>; + +def : LoadPatNoOffset; +def : LoadPatNoOffset; +def : LoadPatNoOffset; +def : LoadPatNoOffset; + // Select loads with a constant offset. -def : Pat<(i32 (load (regPlusImm I32:$addr, imm:$off))), - (LOAD_I32 0, imm:$off, $addr)>; -def : Pat<(i64 (load (regPlusImm I32:$addr, imm:$off))), - (LOAD_I64 0, imm:$off, $addr)>; -def : Pat<(f32 (load (regPlusImm I32:$addr, imm:$off))), - (LOAD_F32 0, imm:$off, $addr)>; -def : Pat<(f64 (load (regPlusImm I32:$addr, imm:$off))), - (LOAD_F64 0, imm:$off, $addr)>; -def : Pat<(i32 (load (or_is_add I32:$addr, imm:$off))), - (LOAD_I32 0, imm:$off, $addr)>; -def : Pat<(i64 (load (or_is_add I32:$addr, imm:$off))), - (LOAD_I64 0, imm:$off, $addr)>; -def : Pat<(f32 (load (or_is_add I32:$addr, imm:$off))), - (LOAD_F32 0, imm:$off, $addr)>; -def : Pat<(f64 (load (or_is_add I32:$addr, imm:$off))), - (LOAD_F64 0, imm:$off, $addr)>; -def : Pat<(i32 (load (regPlusGA I32:$addr, - (WebAssemblywrapper tglobaladdr:$off)))), - (LOAD_I32 0, tglobaladdr:$off, $addr)>; -def : Pat<(i64 (load (regPlusGA I32:$addr, - (WebAssemblywrapper tglobaladdr:$off)))), - (LOAD_I64 0, tglobaladdr:$off, $addr)>; -def : Pat<(f32 (load (regPlusGA I32:$addr, - (WebAssemblywrapper tglobaladdr:$off)))), - (LOAD_F32 0, tglobaladdr:$off, $addr)>; -def : Pat<(f64 (load (regPlusGA I32:$addr, - (WebAssemblywrapper tglobaladdr:$off)))), - (LOAD_F64 0, tglobaladdr:$off, $addr)>; -def : Pat<(i32 (load (add I32:$addr, (WebAssemblywrapper texternalsym:$off)))), - (LOAD_I32 0, texternalsym:$off, $addr)>; -def : Pat<(i64 (load (add I32:$addr, (WebAssemblywrapper texternalsym:$off)))), - (LOAD_I64 0, texternalsym:$off, $addr)>; -def : Pat<(f32 (load (add I32:$addr, (WebAssemblywrapper texternalsym:$off)))), - (LOAD_F32 0, texternalsym:$off, $addr)>; -def : Pat<(f64 (load (add I32:$addr, (WebAssemblywrapper texternalsym:$off)))), - (LOAD_F64 0, texternalsym:$off, $addr)>; + +// Pattern with address + immediate offset +class LoadPatImmOff : + Pat<(ty (loadkind (operand I32:$addr, imm:$off))), + (inst 0, imm:$off, $addr)>; + +def : LoadPatImmOff; +def : LoadPatImmOff; +def : LoadPatImmOff; +def : LoadPatImmOff; +def : LoadPatImmOff; +def : LoadPatImmOff; +def : LoadPatImmOff; +def : LoadPatImmOff; + +class LoadPatGlobalAddr : + Pat<(ty (loadkind (regPlusGA I32:$addr, (WebAssemblywrapper tglobaladdr:$off)))), + (inst 0, tglobaladdr:$off, $addr)>; + +def : LoadPatGlobalAddr; +def : LoadPatGlobalAddr; +def : LoadPatGlobalAddr; +def : LoadPatGlobalAddr; + +class LoadPatExternalSym : + Pat<(ty (loadkind (add I32:$addr, (WebAssemblywrapper texternalsym:$off)))), + (inst 0, texternalsym:$off, $addr)>; +def : LoadPatExternalSym; +def : LoadPatExternalSym; +def : LoadPatExternalSym; +def : LoadPatExternalSym; + // Select loads with just a constant offset. -def : Pat<(i32 (load imm:$off)), (LOAD_I32 0, imm:$off, (CONST_I32 0))>; -def : Pat<(i64 (load imm:$off)), (LOAD_I64 0, imm:$off, (CONST_I32 0))>; -def : Pat<(f32 (load imm:$off)), (LOAD_F32 0, imm:$off, (CONST_I32 0))>; -def : Pat<(f64 (load imm:$off)), (LOAD_F64 0, imm:$off, (CONST_I32 0))>; -def : Pat<(i32 (load (WebAssemblywrapper tglobaladdr:$off))), - (LOAD_I32 0, tglobaladdr:$off, (CONST_I32 0))>; -def : Pat<(i64 (load (WebAssemblywrapper tglobaladdr:$off))), - (LOAD_I64 0, tglobaladdr:$off, (CONST_I32 0))>; -def : Pat<(f32 (load (WebAssemblywrapper tglobaladdr:$off))), - (LOAD_F32 0, tglobaladdr:$off, (CONST_I32 0))>; -def : Pat<(f64 (load (WebAssemblywrapper tglobaladdr:$off))), - (LOAD_F64 0, tglobaladdr:$off, (CONST_I32 0))>; -def : Pat<(i32 (load (WebAssemblywrapper texternalsym:$off))), - (LOAD_I32 0, texternalsym:$off, (CONST_I32 0))>; -def : Pat<(i64 (load (WebAssemblywrapper texternalsym:$off))), - (LOAD_I64 0, texternalsym:$off, (CONST_I32 0))>; -def : Pat<(f32 (load (WebAssemblywrapper texternalsym:$off))), - (LOAD_F32 0, texternalsym:$off, (CONST_I32 0))>; -def : Pat<(f64 (load (WebAssemblywrapper texternalsym:$off))), - (LOAD_F64 0, texternalsym:$off, (CONST_I32 0))>; +class LoadPatOffsetOnly : + Pat<(ty (loadkind imm:$off)), (inst 0, imm:$off, (CONST_I32 0))>; + +def : LoadPatOffsetOnly; +def : LoadPatOffsetOnly; +def : LoadPatOffsetOnly; +def : LoadPatOffsetOnly; + +class LoadPatGlobalAddrOffOnly : + Pat<(ty (loadkind (WebAssemblywrapper tglobaladdr:$off))), + (inst 0, tglobaladdr:$off, (CONST_I32 0))>; + +def : LoadPatGlobalAddrOffOnly; +def : LoadPatGlobalAddrOffOnly; +def : LoadPatGlobalAddrOffOnly; +def : LoadPatGlobalAddrOffOnly; + +class LoadPatExternSymOffOnly : + Pat<(ty (loadkind (WebAssemblywrapper texternalsym:$off))), + (inst 0, texternalsym:$off, (CONST_I32 0))>; +def : LoadPatExternSymOffOnly; +def : LoadPatExternSymOffOnly; +def : LoadPatExternSymOffOnly; +def : LoadPatExternSymOffOnly; let Defs = [ARGUMENTS] in { @@ -176,274 +187,150 @@ } // Defs = [ARGUMENTS] // Select extending loads with no constant offset. -def : Pat<(i32 (sextloadi8 I32:$addr)), (LOAD8_S_I32 0, 0, $addr)>; -def : Pat<(i32 (zextloadi8 I32:$addr)), (LOAD8_U_I32 0, 0, $addr)>; -def : Pat<(i32 (sextloadi16 I32:$addr)), (LOAD16_S_I32 0, 0, $addr)>; -def : Pat<(i32 (zextloadi16 I32:$addr)), (LOAD16_U_I32 0, 0, $addr)>; -def : Pat<(i64 (sextloadi8 I32:$addr)), (LOAD8_S_I64 0, 0, $addr)>; -def : Pat<(i64 (zextloadi8 I32:$addr)), (LOAD8_U_I64 0, 0, $addr)>; -def : Pat<(i64 (sextloadi16 I32:$addr)), (LOAD16_S_I64 0, 0, $addr)>; -def : Pat<(i64 (zextloadi16 I32:$addr)), (LOAD16_U_I64 0, 0, $addr)>; -def : Pat<(i64 (sextloadi32 I32:$addr)), (LOAD32_S_I64 0, 0, $addr)>; -def : Pat<(i64 (zextloadi32 I32:$addr)), (LOAD32_U_I64 0, 0, $addr)>; +def : LoadPatNoOffset; +def : LoadPatNoOffset; +def : LoadPatNoOffset; +def : LoadPatNoOffset; +def : LoadPatNoOffset; +def : LoadPatNoOffset; +def : LoadPatNoOffset; +def : LoadPatNoOffset; +def : LoadPatNoOffset; +def : LoadPatNoOffset; // Select extending loads with a constant offset. -def : Pat<(i32 (sextloadi8 (regPlusImm I32:$addr, imm:$off))), - (LOAD8_S_I32 0, imm:$off, $addr)>; -def : Pat<(i32 (zextloadi8 (regPlusImm I32:$addr, imm:$off))), - (LOAD8_U_I32 0, imm:$off, $addr)>; -def : Pat<(i32 (sextloadi16 (regPlusImm I32:$addr, imm:$off))), - (LOAD16_S_I32 0, imm:$off, $addr)>; -def : Pat<(i32 (zextloadi16 (regPlusImm I32:$addr, imm:$off))), - (LOAD16_U_I32 0, imm:$off, $addr)>; -def : Pat<(i64 (sextloadi8 (regPlusImm I32:$addr, imm:$off))), - (LOAD8_S_I64 0, imm:$off, $addr)>; -def : Pat<(i64 (zextloadi8 (regPlusImm I32:$addr, imm:$off))), - (LOAD8_U_I64 0, imm:$off, $addr)>; -def : Pat<(i64 (sextloadi16 (regPlusImm I32:$addr, imm:$off))), - (LOAD16_S_I64 0, imm:$off, $addr)>; -def : Pat<(i64 (zextloadi16 (regPlusImm I32:$addr, imm:$off))), - (LOAD16_U_I64 0, imm:$off, $addr)>; -def : Pat<(i64 (sextloadi32 (regPlusImm I32:$addr, imm:$off))), - (LOAD32_S_I64 0, imm:$off, $addr)>; -def : Pat<(i64 (zextloadi32 (regPlusImm I32:$addr, imm:$off))), - (LOAD32_U_I64 0, imm:$off, $addr)>; -def : Pat<(i32 (sextloadi8 (or_is_add I32:$addr, imm:$off))), - (LOAD8_S_I32 0, imm:$off, $addr)>; -def : Pat<(i32 (zextloadi8 (or_is_add I32:$addr, imm:$off))), - (LOAD8_U_I32 0, imm:$off, $addr)>; -def : Pat<(i32 (sextloadi16 (or_is_add I32:$addr, imm:$off))), - (LOAD16_S_I32 0, imm:$off, $addr)>; -def : Pat<(i32 (zextloadi16 (or_is_add I32:$addr, imm:$off))), - (LOAD16_U_I32 0, imm:$off, $addr)>; -def : Pat<(i64 (sextloadi8 (or_is_add I32:$addr, imm:$off))), - (LOAD8_S_I64 0, imm:$off, $addr)>; -def : Pat<(i64 (zextloadi8 (or_is_add I32:$addr, imm:$off))), - (LOAD8_U_I64 0, imm:$off, $addr)>; -def : Pat<(i64 (sextloadi16 (or_is_add I32:$addr, imm:$off))), - (LOAD16_S_I64 0, imm:$off, $addr)>; -def : Pat<(i64 (zextloadi16 (or_is_add I32:$addr, imm:$off))), - (LOAD16_U_I64 0, imm:$off, $addr)>; -def : Pat<(i64 (sextloadi32 (or_is_add I32:$addr, imm:$off))), - (LOAD32_S_I64 0, imm:$off, $addr)>; -def : Pat<(i64 (zextloadi32 (or_is_add I32:$addr, imm:$off))), - (LOAD32_U_I64 0, imm:$off, $addr)>; -def : Pat<(i32 (sextloadi8 (regPlusGA I32:$addr, - (WebAssemblywrapper tglobaladdr:$off)))), - (LOAD8_S_I32 0, tglobaladdr:$off, $addr)>; -def : Pat<(i32 (zextloadi8 (regPlusGA I32:$addr, - (WebAssemblywrapper tglobaladdr:$off)))), - (LOAD8_U_I32 0, tglobaladdr:$off, $addr)>; -def : Pat<(i32 (sextloadi16 (regPlusGA I32:$addr, - (WebAssemblywrapper tglobaladdr:$off)))), - (LOAD16_S_I32 0, tglobaladdr:$off, $addr)>; -def : Pat<(i32 (zextloadi16 (regPlusGA I32:$addr, - (WebAssemblywrapper tglobaladdr:$off)))), - (LOAD16_U_I32 0, tglobaladdr:$off, $addr)>; -def : Pat<(i64 (sextloadi8 (regPlusGA I32:$addr, - (WebAssemblywrapper tglobaladdr:$off)))), - (LOAD8_S_I64 0, tglobaladdr:$off, $addr)>; -def : Pat<(i64 (zextloadi8 (regPlusGA I32:$addr, - (WebAssemblywrapper tglobaladdr:$off)))), - (LOAD8_U_I64 0, tglobaladdr:$off, $addr)>; -def : Pat<(i64 (sextloadi16 (regPlusGA I32:$addr, - (WebAssemblywrapper tglobaladdr:$off)))), - (LOAD16_S_I64 0, tglobaladdr:$off, $addr)>; -def : Pat<(i64 (zextloadi16 (regPlusGA I32:$addr, - (WebAssemblywrapper tglobaladdr:$off)))), - (LOAD16_U_I64 0, tglobaladdr:$off, $addr)>; -def : Pat<(i64 (sextloadi32 (regPlusGA I32:$addr, - (WebAssemblywrapper tglobaladdr:$off)))), - (LOAD32_S_I64 0, tglobaladdr:$off, $addr)>; -def : Pat<(i64 (zextloadi32 (regPlusGA I32:$addr, - (WebAssemblywrapper tglobaladdr:$off)))), - (LOAD32_U_I64 0, tglobaladdr:$off, $addr)>; -def : Pat<(i32 (sextloadi8 (add I32:$addr, - (WebAssemblywrapper texternalsym:$off)))), - (LOAD8_S_I32 0, texternalsym:$off, $addr)>; -def : Pat<(i32 (zextloadi8 (add I32:$addr, - (WebAssemblywrapper texternalsym:$off)))), - (LOAD8_U_I32 0, texternalsym:$off, $addr)>; -def : Pat<(i32 (sextloadi16 (add I32:$addr, - (WebAssemblywrapper texternalsym:$off)))), - (LOAD16_S_I32 0, texternalsym:$off, $addr)>; -def : Pat<(i32 (zextloadi16 (add I32:$addr, - (WebAssemblywrapper texternalsym:$off)))), - (LOAD16_U_I32 0, texternalsym:$off, $addr)>; -def : Pat<(i64 (sextloadi8 (add I32:$addr, - (WebAssemblywrapper texternalsym:$off)))), - (LOAD8_S_I64 0, texternalsym:$off, $addr)>; -def : Pat<(i64 (zextloadi8 (add I32:$addr, - (WebAssemblywrapper texternalsym:$off)))), - (LOAD8_U_I64 0, texternalsym:$off, $addr)>; -def : Pat<(i64 (sextloadi16 (add I32:$addr, - (WebAssemblywrapper texternalsym:$off)))), - (LOAD16_S_I64 0, texternalsym:$off, $addr)>; -def : Pat<(i64 (zextloadi16 (add I32:$addr, - (WebAssemblywrapper texternalsym:$off)))), - (LOAD16_U_I64 0, texternalsym:$off, $addr)>; -def : Pat<(i64 (sextloadi32 (add I32:$addr, - (WebAssemblywrapper texternalsym:$off)))), - (LOAD32_S_I64 0, texternalsym:$off, $addr)>; -def : Pat<(i64 (zextloadi32 (add I32:$addr, - (WebAssemblywrapper texternalsym:$off)))), - (LOAD32_U_I64 0, texternalsym:$off, $addr)>; +def : LoadPatImmOff; +def : LoadPatImmOff; +def : LoadPatImmOff; +def : LoadPatImmOff; +def : LoadPatImmOff; +def : LoadPatImmOff; +def : LoadPatImmOff; +def : LoadPatImmOff; +def : LoadPatImmOff; +def : LoadPatImmOff; + +def : LoadPatImmOff; +def : LoadPatImmOff; +def : LoadPatImmOff; +def : LoadPatImmOff; +def : LoadPatImmOff; +def : LoadPatImmOff; +def : LoadPatImmOff; +def : LoadPatImmOff; +def : LoadPatImmOff; +def : LoadPatImmOff; + +def : LoadPatGlobalAddr; +def : LoadPatGlobalAddr; +def : LoadPatGlobalAddr; +def : LoadPatGlobalAddr; + +def : LoadPatGlobalAddr; +def : LoadPatGlobalAddr; +def : LoadPatGlobalAddr; +def : LoadPatGlobalAddr; +def : LoadPatGlobalAddr; +def : LoadPatGlobalAddr; + +def : LoadPatExternalSym; +def : LoadPatExternalSym; +def : LoadPatExternalSym; +def : LoadPatExternalSym; +def : LoadPatExternalSym; +def : LoadPatExternalSym; +def : LoadPatExternalSym; +def : LoadPatExternalSym; +def : LoadPatExternalSym; +def : LoadPatExternalSym; + // Select extending loads with just a constant offset. -def : Pat<(i32 (sextloadi8 imm:$off)), - (LOAD8_S_I32 0, imm:$off, (CONST_I32 0))>; -def : Pat<(i32 (zextloadi8 imm:$off)), - (LOAD8_U_I32 0, imm:$off, (CONST_I32 0))>; -def : Pat<(i32 (sextloadi16 imm:$off)), - (LOAD16_S_I32 0, imm:$off, (CONST_I32 0))>; -def : Pat<(i32 (zextloadi16 imm:$off)), - (LOAD16_U_I32 0, imm:$off, (CONST_I32 0))>; -def : Pat<(i64 (sextloadi8 imm:$off)), - (LOAD8_S_I64 0, imm:$off, (CONST_I32 0))>; -def : Pat<(i64 (zextloadi8 imm:$off)), - (LOAD8_U_I64 0, imm:$off, (CONST_I32 0))>; -def : Pat<(i64 (sextloadi16 imm:$off)), - (LOAD16_S_I64 0, imm:$off, (CONST_I32 0))>; -def : Pat<(i64 (zextloadi16 imm:$off)), - (LOAD16_U_I64 0, imm:$off, (CONST_I32 0))>; -def : Pat<(i64 (sextloadi32 imm:$off)), - (LOAD32_S_I64 0, imm:$off, (CONST_I32 0))>; -def : Pat<(i64 (zextloadi32 imm:$off)), - (LOAD32_U_I64 0, imm:$off, (CONST_I32 0))>; -def : Pat<(i32 (sextloadi8 (WebAssemblywrapper tglobaladdr:$off))), - (LOAD8_S_I32 0, tglobaladdr:$off, (CONST_I32 0))>; -def : Pat<(i32 (zextloadi8 (WebAssemblywrapper tglobaladdr:$off))), - (LOAD8_U_I32 0, tglobaladdr:$off, (CONST_I32 0))>; -def : Pat<(i32 (sextloadi16 (WebAssemblywrapper tglobaladdr:$off))), - (LOAD16_S_I32 0, tglobaladdr:$off, (CONST_I32 0))>; -def : Pat<(i32 (zextloadi16 (WebAssemblywrapper tglobaladdr:$off))), - (LOAD16_U_I32 0, tglobaladdr:$off, (CONST_I32 0))>; -def : Pat<(i64 (sextloadi8 (WebAssemblywrapper tglobaladdr:$off))), - (LOAD8_S_I64 0, tglobaladdr:$off, (CONST_I32 0))>; -def : Pat<(i64 (zextloadi8 (WebAssemblywrapper tglobaladdr:$off))), - (LOAD8_U_I64 0, tglobaladdr:$off, (CONST_I32 0))>; -def : Pat<(i64 (sextloadi16 (WebAssemblywrapper tglobaladdr:$off))), - (LOAD16_S_I64 0, tglobaladdr:$off, (CONST_I32 0))>; -def : Pat<(i64 (zextloadi16 (WebAssemblywrapper tglobaladdr:$off))), - (LOAD16_U_I64 0, tglobaladdr:$off, (CONST_I32 0))>; -def : Pat<(i64 (sextloadi32 (WebAssemblywrapper tglobaladdr:$off))), - (LOAD32_S_I64 0, tglobaladdr:$off, (CONST_I32 0))>; -def : Pat<(i64 (zextloadi32 (WebAssemblywrapper tglobaladdr:$off))), - (LOAD32_U_I64 0, tglobaladdr:$off, (CONST_I32 0))>; -def : Pat<(i32 (sextloadi8 (WebAssemblywrapper texternalsym:$off))), - (LOAD8_S_I32 0, texternalsym:$off, (CONST_I32 0))>; -def : Pat<(i32 (zextloadi8 (WebAssemblywrapper texternalsym:$off))), - (LOAD8_U_I32 0, texternalsym:$off, (CONST_I32 0))>; -def : Pat<(i32 (sextloadi16 (WebAssemblywrapper texternalsym:$off))), - (LOAD16_S_I32 0, texternalsym:$off, (CONST_I32 0))>; -def : Pat<(i32 (zextloadi16 (WebAssemblywrapper texternalsym:$off))), - (LOAD16_U_I32 0, texternalsym:$off, (CONST_I32 0))>; -def : Pat<(i64 (sextloadi8 (WebAssemblywrapper texternalsym:$off))), - (LOAD8_S_I64 0, texternalsym:$off, (CONST_I32 0))>; -def : Pat<(i64 (zextloadi8 (WebAssemblywrapper texternalsym:$off))), - (LOAD8_U_I64 0, texternalsym:$off, (CONST_I32 0))>; -def : Pat<(i64 (sextloadi16 (WebAssemblywrapper texternalsym:$off))), - (LOAD16_S_I64 0, texternalsym:$off, (CONST_I32 0))>; -def : Pat<(i64 (zextloadi16 (WebAssemblywrapper texternalsym:$off))), - (LOAD16_U_I64 0, texternalsym:$off, (CONST_I32 0))>; -def : Pat<(i64 (sextloadi32 (WebAssemblywrapper texternalsym:$off))), - (LOAD32_S_I64 0, texternalsym:$off, (CONST_I32 0))>; -def : Pat<(i64 (zextloadi32 (WebAssemblywrapper texternalsym:$off))), - (LOAD32_U_I64 0, texternalsym:$off, (CONST_I32 0))>; +def : LoadPatOffsetOnly; +def : LoadPatOffsetOnly; +def : LoadPatOffsetOnly; +def : LoadPatOffsetOnly; + +def : LoadPatOffsetOnly; +def : LoadPatOffsetOnly; +def : LoadPatOffsetOnly; +def : LoadPatOffsetOnly; +def : LoadPatOffsetOnly; +def : LoadPatOffsetOnly; + +def : LoadPatGlobalAddrOffOnly; +def : LoadPatGlobalAddrOffOnly; +def : LoadPatGlobalAddrOffOnly; +def : LoadPatGlobalAddrOffOnly; +def : LoadPatGlobalAddrOffOnly; +def : LoadPatGlobalAddrOffOnly; +def : LoadPatGlobalAddrOffOnly; +def : LoadPatGlobalAddrOffOnly; +def : LoadPatGlobalAddrOffOnly; +def : LoadPatGlobalAddrOffOnly; + +def : LoadPatExternSymOffOnly; +def : LoadPatExternSymOffOnly; +def : LoadPatExternSymOffOnly; +def : LoadPatExternSymOffOnly; +def : LoadPatExternSymOffOnly; +def : LoadPatExternSymOffOnly; +def : LoadPatExternSymOffOnly; +def : LoadPatExternSymOffOnly; +def : LoadPatExternSymOffOnly; +def : LoadPatExternSymOffOnly; // Resolve "don't care" extending loads to zero-extending loads. This is // somewhat arbitrary, but zero-extending is conceptually simpler. // Select "don't care" extending loads with no constant offset. -def : Pat<(i32 (extloadi8 I32:$addr)), (LOAD8_U_I32 0, 0, $addr)>; -def : Pat<(i32 (extloadi16 I32:$addr)), (LOAD16_U_I32 0, 0, $addr)>; -def : Pat<(i64 (extloadi8 I32:$addr)), (LOAD8_U_I64 0, 0, $addr)>; -def : Pat<(i64 (extloadi16 I32:$addr)), (LOAD16_U_I64 0, 0, $addr)>; -def : Pat<(i64 (extloadi32 I32:$addr)), (LOAD32_U_I64 0, 0, $addr)>; +def : LoadPatNoOffset; +def : LoadPatNoOffset; +def : LoadPatNoOffset; +def : LoadPatNoOffset; +def : LoadPatNoOffset; + // Select "don't care" extending loads with a constant offset. -def : Pat<(i32 (extloadi8 (regPlusImm I32:$addr, imm:$off))), - (LOAD8_U_I32 0, imm:$off, $addr)>; -def : Pat<(i32 (extloadi16 (regPlusImm I32:$addr, imm:$off))), - (LOAD16_U_I32 0, imm:$off, $addr)>; -def : Pat<(i64 (extloadi8 (regPlusImm I32:$addr, imm:$off))), - (LOAD8_U_I64 0, imm:$off, $addr)>; -def : Pat<(i64 (extloadi16 (regPlusImm I32:$addr, imm:$off))), - (LOAD16_U_I64 0, imm:$off, $addr)>; -def : Pat<(i64 (extloadi32 (regPlusImm I32:$addr, imm:$off))), - (LOAD32_U_I64 0, imm:$off, $addr)>; -def : Pat<(i32 (extloadi8 (or_is_add I32:$addr, imm:$off))), - (LOAD8_U_I32 0, imm:$off, $addr)>; -def : Pat<(i32 (extloadi16 (or_is_add I32:$addr, imm:$off))), - (LOAD16_U_I32 0, imm:$off, $addr)>; -def : Pat<(i64 (extloadi8 (or_is_add I32:$addr, imm:$off))), - (LOAD8_U_I64 0, imm:$off, $addr)>; -def : Pat<(i64 (extloadi16 (or_is_add I32:$addr, imm:$off))), - (LOAD16_U_I64 0, imm:$off, $addr)>; -def : Pat<(i64 (extloadi32 (or_is_add I32:$addr, imm:$off))), - (LOAD32_U_I64 0, imm:$off, $addr)>; -def : Pat<(i32 (extloadi8 (regPlusGA I32:$addr, - (WebAssemblywrapper tglobaladdr:$off)))), - (LOAD8_U_I32 0, tglobaladdr:$off, $addr)>; -def : Pat<(i32 (extloadi16 (regPlusGA I32:$addr, - (WebAssemblywrapper tglobaladdr:$off)))), - (LOAD16_U_I32 0, tglobaladdr:$off, $addr)>; -def : Pat<(i64 (extloadi8 (regPlusGA I32:$addr, - (WebAssemblywrapper tglobaladdr:$off)))), - (LOAD8_U_I64 0, tglobaladdr:$off, $addr)>; -def : Pat<(i64 (extloadi16 (regPlusGA I32:$addr, - (WebAssemblywrapper tglobaladdr:$off)))), - (LOAD16_U_I64 0, tglobaladdr:$off, $addr)>; -def : Pat<(i64 (extloadi32 (regPlusGA I32:$addr, - (WebAssemblywrapper tglobaladdr:$off)))), - (LOAD32_U_I64 0, tglobaladdr:$off, $addr)>; -def : Pat<(i32 (extloadi8 (add I32:$addr, - (WebAssemblywrapper texternalsym:$off)))), - (LOAD8_U_I32 0, texternalsym:$off, $addr)>; -def : Pat<(i32 (extloadi16 (add I32:$addr, - (WebAssemblywrapper texternalsym:$off)))), - (LOAD16_U_I32 0, texternalsym:$off, $addr)>; -def : Pat<(i64 (extloadi8 (add I32:$addr, - (WebAssemblywrapper texternalsym:$off)))), - (LOAD8_U_I64 0, texternalsym:$off, $addr)>; -def : Pat<(i64 (extloadi16 (add I32:$addr, - (WebAssemblywrapper texternalsym:$off)))), - (LOAD16_U_I64 0, texternalsym:$off, $addr)>; -def : Pat<(i64 (extloadi32 (add I32:$addr, - (WebAssemblywrapper texternalsym:$off)))), - (LOAD32_U_I64 0, texternalsym:$off, $addr)>; +def : LoadPatImmOff; +def : LoadPatImmOff; +def : LoadPatImmOff; +def : LoadPatImmOff; +def : LoadPatImmOff; +def : LoadPatImmOff; +def : LoadPatImmOff; +def : LoadPatImmOff; +def : LoadPatImmOff; +def : LoadPatImmOff; +def : LoadPatGlobalAddr; +def : LoadPatGlobalAddr; +def : LoadPatGlobalAddr; +def : LoadPatGlobalAddr; +def : LoadPatGlobalAddr; +def : LoadPatExternalSym; +def : LoadPatExternalSym; +def : LoadPatExternalSym; +def : LoadPatExternalSym; +def : LoadPatExternalSym; + // Select "don't care" extending loads with just a constant offset. -def : Pat<(i32 (extloadi8 imm:$off)), - (LOAD8_U_I32 0, imm:$off, (CONST_I32 0))>; -def : Pat<(i32 (extloadi16 imm:$off)), - (LOAD16_U_I32 0, imm:$off, (CONST_I32 0))>; -def : Pat<(i64 (extloadi8 imm:$off)), - (LOAD8_U_I64 0, imm:$off, (CONST_I32 0))>; -def : Pat<(i64 (extloadi16 imm:$off)), - (LOAD16_U_I64 0, imm:$off, (CONST_I32 0))>; -def : Pat<(i64 (extloadi32 imm:$off)), - (LOAD32_U_I64 0, imm:$off, (CONST_I32 0))>; -def : Pat<(i32 (extloadi8 (WebAssemblywrapper tglobaladdr:$off))), - (LOAD8_U_I32 0, tglobaladdr:$off, (CONST_I32 0))>; -def : Pat<(i32 (extloadi16 (WebAssemblywrapper tglobaladdr:$off))), - (LOAD16_U_I32 0, tglobaladdr:$off, (CONST_I32 0))>; -def : Pat<(i64 (extloadi8 (WebAssemblywrapper tglobaladdr:$off))), - (LOAD8_U_I64 0, tglobaladdr:$off, (CONST_I32 0))>; -def : Pat<(i64 (extloadi16 (WebAssemblywrapper tglobaladdr:$off))), - (LOAD16_U_I64 0, tglobaladdr:$off, (CONST_I32 0))>; -def : Pat<(i64 (extloadi32 (WebAssemblywrapper tglobaladdr:$off))), - (LOAD32_U_I64 0, tglobaladdr:$off, (CONST_I32 0))>; -def : Pat<(i32 (extloadi8 (WebAssemblywrapper texternalsym:$off))), - (LOAD8_U_I32 0, texternalsym:$off, (CONST_I32 0))>; -def : Pat<(i32 (extloadi16 (WebAssemblywrapper texternalsym:$off))), - (LOAD16_U_I32 0, texternalsym:$off, (CONST_I32 0))>; -def : Pat<(i64 (extloadi8 (WebAssemblywrapper texternalsym:$off))), - (LOAD8_U_I64 0, texternalsym:$off, (CONST_I32 0))>; -def : Pat<(i64 (extloadi16 (WebAssemblywrapper texternalsym:$off))), - (LOAD16_U_I64 0, texternalsym:$off, (CONST_I32 0))>; -def : Pat<(i64 (extloadi32 (WebAssemblywrapper texternalsym:$off))), - (LOAD32_U_I64 0, tglobaladdr:$off, (CONST_I32 0))>; +def : LoadPatOffsetOnly; +def : LoadPatOffsetOnly; +def : LoadPatOffsetOnly; +def : LoadPatOffsetOnly; +def : LoadPatOffsetOnly; +def : LoadPatGlobalAddrOffOnly; +def : LoadPatGlobalAddrOffOnly; +def : LoadPatGlobalAddrOffOnly; +def : LoadPatGlobalAddrOffOnly; +def : LoadPatGlobalAddrOffOnly; +def : LoadPatExternSymOffOnly; +def : LoadPatExternSymOffOnly; +def : LoadPatExternSymOffOnly; +def : LoadPatExternSymOffOnly; +def : LoadPatExternSymOffOnly; + let Defs = [ARGUMENTS] in { Index: test/CodeGen/WebAssembly/atomics.ll =================================================================== --- test/CodeGen/WebAssembly/atomics.ll +++ test/CodeGen/WebAssembly/atomics.ll @@ -1,5 +1,5 @@ ; RUN: not llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -mattr=+atomics | FileCheck %s +; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -disable-wasm-explicit-locals -mattr=+atomics | FileCheck %s ; Test that atomic loads are assembled properly. @@ -7,10 +7,7 @@ target triple = "wasm32-unknown-unknown-wasm" ; CHECK-LABEL: load_i32_atomic: -; CHECK-NEXT: .param i32{{$}} -; CHECK-NEXT: .result i32{{$}} -; CHECK-NEXT: get_local $push[[L0:[0-9]+]]=, 0{{$}} -; CHECK-NEXT: i32.atomic.load $push[[NUM:[0-9]+]]=, 0($pop[[L0]]){{$}} +; CHECK: i32.atomic.load $push[[NUM:[0-9]+]]=, 0($0){{$}} ; CHECK-NEXT: return $pop[[NUM]]{{$}} define i32 @load_i32_atomic(i32 *%p) {