Skip to content

[Bug] TGATHER compare form lowering drops the offset argument, causing C++ compile failure #654

@Little-oil

Description

@Little-oil

Component

PTO Dialect / ODS (include/PTO/IR)

Description

The compare form of pto.gather (with a CmpMode) is lowered incorrectly to the C++ TGATHER template call: the offset argument is placed into the template non-type parameter list instead of being passed as a runtime function argument. The resulting call does not match the real TGATHER signature and fails to compile.

Reproduction (minimal)

func.func @main(
    %src:  !pto.tile<vec, i32, 16x64, row_major, none_box, null, null>,
    %kv:   !pto.tile<vec, f16, 1x1,   row_major, none_box, null, null>,
    %tmp:  !pto.tile<vec, i32, 1x16,  row_major, none_box, null, null>,
    %dst:  !pto.tile<vec, i32, 16x8,  row_major, none_box, null, null>,
    %cdst: !pto.tile<vec, u8,  16x64, row_major, none_box, null, null>
) {
  pto.tgather ins(%src, %kv, %tmp : ...) outs(%dst, %cdst : ...)
              {cmpMode = #pto<cmp gt>, offset = 0 : i32}
  return
}

Expected behavior

offset is emitted as the last runtime function argument; the template parameter list ends at CmpMode:

// 6 runtime args — matches TGATHER signature
TGATHER<
  Tile<TileType::Vec, int32_t, 16, 8,  BLayout::RowMajor, -1, -1, SLayout::NoneBox, 512, PadValue::Null, CompactMode::Null>,
  Tile<TileType::Vec, half,    16, 64, BLayout::RowMajor, -1, -1, SLayout::NoneBox, 512, PadValue::Null, CompactMode::Null>,
  Tile<TileType::Vec, int32_t, 1,  16, BLayout::RowMajor, -1, -1, SLayout::NoneBox, 512, PadValue::Null, CompactMode::Null>,
  Tile<TileType::Vec, uint8_t, 16, 64, BLayout::RowMajor, -1, -1, SLayout::NoneBox, 512, PadValue::Null, CompactMode::Null>,
  CmpMode::GT
>(v28, v17, v15, v32, v24, 0);

Actual behavior / error logs

`offset` is placed in the **template** parameter list as a trailing non-type argument `0`, and the call only passes **5** runtime arguments:


// 5 runtime args, trailing `0` in template list — no matching overload
TGATHER<
  Tile<TileType::Vec, int32_t, 16, 8,  BLayout::RowMajor, -1, -1, SLayout::NoneBox, 512, PadValue::Null, CompactMode::Null>,
  Tile<TileType::Vec, half,    16, 64, BLayout::RowMajor, -1, -1, SLayout::NoneBox, 512, PadValue::Null, CompactMode::Null>,
  Tile<TileType::Vec, int32_t, 1,  16, BLayout::RowMajor, -1, -1, SLayout::NoneBox, 512, PadValue::Null, CompactMode::Null>,
  Tile<TileType::Vec, uint8_t, 16, 64, BLayout::RowMajor, -1, -1, SLayout::NoneBox, 512, PadValue::Null, CompactMode::Null>,
  CmpMode::GT, 0
>(v28, v17, v15, v32, v24);


Compiler error:


error: no matching function for call to 'TGATHER'


---

Git commit

Host platform

None

Target Ascend arch (if relevant)

None

PTOAS build level (if relevant)

None

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status

In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions