[llvm] [AMDGPU] Fuse dword load + sign/zero-extension into subword load (PR #219019)

Krzysztof Drewniak via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 26 12:53:33 PDT 2026


================
@@ -2861,6 +2881,122 @@ bool SILoadStoreOptimizerLegacy::runOnMachineFunction(MachineFunction &MF) {
       .run(MF);
 }
 
+enum SubwordExtensionType {
+  EXT_U8 = 0,
+  EXT_U16 = 1,
+  EXT_I8 = 2,
+  EXT_I16 = 3,
+  EXT_NONE = -1
+};
+
+// Determine the extension type based on the use instruction.
+// Returns EXT_NONE if the use pattern doesn't match a subword load.
+static SubwordExtensionType getExtensionType(const MachineInstr *UseInst) {
+  switch (UseInst->getOpcode()) {
+  case AMDGPU::S_AND_B32: {
+    // Check if it's masking with 0xff or 0xffff
+    const MachineOperand &MaskOp = UseInst->getOperand(2);
----------------
krzysz00 wrote:

How do we know it'll be the second operand?

And what about more complex cases, like lshl_and?

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


More information about the llvm-commits mailing list