[llvm] [PowerPC] Add bctar instruction (ISA 2.07) (PR #187322)

via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 16 18:11:59 PDT 2026


Scottcjn wrote:

Thanks for the review @lei137 — pushed both fixes so both **32-bit and 64-bit** are properly covered now:

**Coverage after these commits:**

| Mode | Non-linking | Linking | File |
|---|---|---|---|
| 32-bit | `BCCTAR`  (existing, no Defs) | `BCCTARL`  (existing, `Defs=[LR]`)  | `PPCInstrInfo.td` |
| 64-bit | `BCCTAR8` (new, no Defs)      | `BCCTARL8` (new, `Defs=[LR8]`)      | `PPCInstr64Bit.td` |

Both coexist, mirroring the existing `BCCCTR`/`BCCCTR8` and `BCCCTRL`/`BCCCTRL8` split. Neither is gated with `Requires<[IsPPC32/64]>` on the 32-bit side — same as `BCCCTRL` — because these are `isCodeGenOnly` and emitted directly by `PPCISelLowering` against the current subtarget rather than going through the matcher.

**1. 64-bit variants (BCCTAR8 / BCCTARL8)** — 3dd27bd

Two new blocks in `PPCInstr64Bit.td`:

- **BCCTAR8** (non-linking): `isTerminator=1, isBarrier=1, PPC970_Unit=7, hasSideEffects=0` → `Predicates=[IsISA2_07]` → `isBranch=1, isIndirectBranch=1` → `isCodeGenOnly=1`, `Requires<[IsPPC64]>`. Shape matches `BCCTR8` exactly (no LR defs, indirect branch semantics).
- **BCCTARL8** (linking): `isCall=1, PPC970_Unit=7, Defs=[LR8], hasSideEffects=0` → `Predicates=[IsISA2_07]` → `Uses=[RM]` → `isCodeGenOnly=1`, `Requires<[IsPPC64]>`. Shape matches `BCCCTRL8` exactly (`Defs=[LR8]` outer, `Uses=[RM]` inner).

The existing 32-bit `BCCTAR`/`BCCTARL` in `PPCInstrInfo.td` are unchanged — kept for 32-bit targets with `Defs=[LR]` on the linking form, matching `BCCCTRL`'s existing 32-bit shape.

**2. Disassembly tests** — 157ed0d

New `llvm/test/MC/Disassembler/PowerPC/ppc64-encoding-bctar.txt` covering both `powerpc64-unknown-unknown` and `powerpc64le-unknown-unknown` with `-mcpu=pwr8`:

- Generic `bctar`/`bctarl` (2-operand and 3-operand)
- Simple mnemonics (`bttar`/`bftar`) decoding as generic `bctar BO, BI`
- Prediction hints (+/-)
- Extended mnemonics that round-trip: `blttar`/`blttarl`, `bgttar`, `beqtar`
- `bdnztar`/`bdztar` source forms decoding as generic `bctar 16/18, 0, 0`

All bytes match the BE encodings already verified in the paired `.s` test, so the BE runline decodes them directly and the LE runline decodes the byte-reversed forms to the same mnemonics.

**Caveat**: these commits were prepared without a local LLVM rebuild (derived from comparing against `BCCCTRL8`'s shape and the existing `.s` test's verified byte table). If the disassembly tests fail in CI I'll iterate on the MC printer's actual output format for the extended mnemonics — current assumption is the printer emits `blttar N` for the BO=12 cases and generic `bctar BO, 0, 0` for the bdnz/bdz BO values, matching the `.s` file's CHECK lines.

Let me know if you want me to also add a 32-bit disassembly test file, or restructure the 64-bit blocks differently.


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


More information about the llvm-commits mailing list