[llvm] [SystemZ] XPLINK64: emit narrow sign/zero-extend instructions for sub-i32 formal args (PR #206833)

Zibi Sarbinowski via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 3 20:41:02 PDT 2026


================
@@ -2152,6 +2152,18 @@ SDValue SystemZTargetLowering::LowerFormalArguments(
           assert(PartOffset && "Offset should be non-zero.");
         }
       }
+    } else if (Subtarget.isTargetXPLINK64() &&
+               (VA.getLocInfo() == CCValAssign::SExt ||
+                VA.getLocInfo() == CCValAssign::ZExt) &&
+               Ins[I].ArgVT.isSimple() &&
+               Ins[I].ArgVT.getSimpleVT().isScalarInteger() &&
+               !Ins[I].Flags.isPointer()) {
----------------
zibi2 wrote:

**Re: isSimple() and non-standard integer types**

I ran a probe with XL C V2.4, Open XL 1.1 and 2.2 compilers all targeting z/OS XPLINK64 using:

```
typedef struct { signed   int v : 24; } s24_t;
typedef struct { unsigned int v : 24; } u24_t;
```

All three compilers agree on the calling convention for these types:

- Caller (caller_24s): sllg 0,1,40 + srag 0,0,40 — shifts the 24-bit value into the high bits of a GR64 before the call

- Callee (callee_24s): srag 0,1,40 — extracts and sign-extends from those high bits on entry

This is the XPLINK64 small-struct layout, not integer extension. The argument goes through struct coercion entirely, never through CCValAssign::SExt/ZExt, so the isSimple() branch is never reached for real C code. 

There is no C primitive of width 24 or 33 bits, etc., so no C compiler — old or new — can produce a bare i24 `signext` integer argument. These types can only appear in hand-written LLVM IR, and for those convertLocVTToValVT is the correct handling.

**Re: !isPointer()** 

__ptr32 argument handling in XPLINK64 — three compilers (verified)
**Callee side**
| Function                        | Open XL 1.1        | Open XL 2.2        | XL V2.4 classic       |
|---------------------------------|--------------------|--------------------|-----------------------|
| use_ptr32 (dereference)         | llgtr 1,1          | llgtr 1,1          | LLGT r1,p(...)        |
| ptr32_to_64 (widen to 64-bit)   | llgtr 0,1          | llgtr 0,1          | LLGT + LLGTR          |
| spill_test (vararg spill of p)  | llgtr 0,2 then stg | lgfr 1,1 then stg  | LGFR + LLGT then STG  |

**Caller side**
| Function                          | Open XL 1.1 | Open XL 2.2  | XL V2.4 classic    |
|-----------------------------------|-------------|--------------|--------------------|
| test_pass_ptr32 (forward arg)     | nothing     | nothing      | LLGT before call   |
| test_pass_ptr32_from_cast (cast)  | nothing     | llgfr 1,1    | LLGFR+LLGT before call |

Both Open XL 1.1 and 2.2 consistently use `llgtr` in the callee when a `__ptr32` is used as an address (clearing bit 32 per the 31-bit addressing rule). On the caller side, Open XL 1.1 emits nothing in either case, and Open XL 2.2 only zero-extends in the cast case — confirming that the callee cannot rely on the incoming register being clean and must always apply `llgtr` itself.

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


More information about the llvm-commits mailing list