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

via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 18 09:28:40 PDT 2026


Scottcjn wrote:

Thanks for the review @lei137. Addressed all three points:

### 1. Disassembly tests

Added in [`157ed0d`](https://github.com/llvm/llvm-project/pull/187322/commits/157ed0dc4c6509470640233cdcdbaac34f891c27) — `llvm/test/MC/Disassembler/PowerPC/ppc64-encoding-bctar.txt` (59 lines) exercises the MC disassembler on both BE and LE `powerpc64` for:
- Generic `bctar`/`bctarl`
- Simple mnemonics (`bttar`/`bftar`)
- Prediction hints (`+`/`-`)
- Extended mnemonics (`blttar`/`bgttar`/`beqtar`/etc.)
- `bdnztar`/`bdztar` forms decoded as generic `bctar` with the appropriate BO values

### 2. 64-bit support (`LR` vs `LR8`)

Good catch — the 32-bit-only `Defs = [LR]` pattern in `PPCInstrInfo.td` was incomplete on its own. [`3dd27bd`](https://github.com/llvm/llvm-project/pull/187322/commits/3dd27bde46a9e76111405e0eadf3169752b5c53d) adds the 64-bit `BCCTAR8`/`BCCTARL8` variants in `PPCInstr64Bit.td`, mirroring the `BCCTR`/`BCCTR8` and `BLR`/`BLR8` splits:

```td
// PPCInstr64Bit.td — BCCTARL8 uses LR8 and is IsPPC64-gated
let isCall = 1, PPC970_Unit = 7, Defs = [LR8], hasSideEffects = 0 in {
  let Predicates = [IsISA2_07] in {
    let Uses = [RM], isCodeGenOnly = 1 in {
      def BCCTARL8 : XLForm_2_br<19, 560, 1, (outs), (ins (pred $BIBO, $CR):$cond),
                                 "b${cond:cc}tarl${cond:pm} ${cond:reg}", IIC_BrB,
                                 []>, Requires<[IsPPC64]>;
    }
  }
}
```

So 32-bit builds get `BCCTAR`/`BCCTARL` with `Defs = [LR]`, and 64-bit builds get `BCCTAR8`/`BCCTARL8` with `Defs = [LR8]`, the same way `BLR`/`BLR8` split.

### 3. `BranchSimpleMnemonic3` → fold into `BranchSimpleMnemonic2`

Agreed, the parallel multiclass was unnecessary. Just pushed [`4655a7d`](https://github.com/llvm/llvm-project/pull/187322/commits/4655a7d526f9) — extend `BranchSimpleMnemonic2` with the ISA 2.07-gated `bctar`/`bctarl` aliases directly, drop `BranchSimpleMnemonic3`, and move the `defm` call sites back to `BranchSimpleMnemonic2`. Net -3 lines, same generated aliases, no behavioral change.

```td
multiclass BranchSimpleMnemonic2<string name, string pm, int bo>
  : BranchSimpleMnemonic1<name, pm, bo> {
  def : InstAlias<"b"#name#"ctr"#pm#" $bi", (gBCCTR bo, crbitrc:$bi, 0)>;
  def : InstAlias<"b"#name#"ctrl"#pm#" $bi", (gBCCTRL bo, crbitrc:$bi, 0)>;
  let Predicates = [IsISA2_07] in {
    def : InstAlias<"b"#name#"tar"#pm#" $bi", (gBCTAR bo, crbitrc:$bi, 0)>;
    def : InstAlias<"b"#name#"tarl"#pm#" $bi", (gBCTARL bo, crbitrc:$bi, 0)>;
  }
}
```

Ready for another look when you have time.

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


More information about the llvm-commits mailing list