Skip to content

Commit 248fc52

Browse files
arshadmclaude
andcommitted
triton: add identity codegen handler for Into::into on tensor types
T::I32Tensor and T::Tensor<i32> share the same MLIR type in LlvmTriton, so Into::into is a no-op at the MLIR level. Pass the argument through unchanged to preserve its static shape in the SSA. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 3549ca0 commit 248fc52

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

  • compiler/rustc_codegen_llvm/src/mlir/codegen/triton/ops

compiler/rustc_codegen_llvm/src/mlir/codegen/triton/ops/terminator.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,10 @@ impl<'a> TritonCodegen<'a> {
372372
TritonCodegen::codegen_max_constancy_call as LocalCallHandler<'a, 'tcx>
373373
}
374374
"triton::Triton::where_" => TritonCodegen::codegen_where_call as LocalCallHandler<'a, 'tcx>,
375+
// `Into::into` for tensor types is an identity conversion at the MLIR level
376+
// (T::I32Tensor and T::Tensor<i32> share the same MLIR type in LlvmTriton).
377+
// Pass the argument through unchanged so the SSA value retains its static shape.
378+
"Into::into" => TritonCodegen::codegen_identity_call as LocalCallHandler<'a, 'tcx>,
375379
"triton::Triton::assume" => TritonCodegen::codegen_assume_call as LocalCallHandler<'a, 'tcx>,
376380
"triton::Triton::device_assert" => {
377381
TritonCodegen::codegen_device_assert_call as LocalCallHandler<'a, 'tcx>
@@ -552,6 +556,35 @@ impl<'a> TritonCodegen<'a> {
552556
Ok(result)
553557
}
554558

559+
/// Identity pass-through for `Into::into` on tensor types.
560+
/// `T::I32Tensor` and `T::Tensor<i32>` are the same MLIR type in `LlvmTriton`;
561+
/// returning the argument unchanged preserves its static shape in the SSA.
562+
#[allow(clippy::too_many_arguments)]
563+
pub fn codegen_identity_call<'tcx>(
564+
&self,
565+
tcx: TyCtxt<'tcx>,
566+
instance: &Instance<'tcx>,
567+
mir: &Body<'tcx>,
568+
_func: &Operand<'tcx>,
569+
_func_name: &str,
570+
args: &[Spanned<Operand<'tcx>>],
571+
_destination: &Place<'tcx>,
572+
_target: &Option<BasicBlock>,
573+
_unwind: &UnwindAction,
574+
_call_source: &CallSource,
575+
_fn_span: &Span,
576+
location: Location<'a>,
577+
mlir_block: &BlockRef<'a, 'a>,
578+
state: &mut CodegenState<'a, 'a>,
579+
) -> Result<Option<Value<'a, 'a>>, MlirError> {
580+
debug_assert!(args.len() == 1, "codegen_identity_call: expected 1 arg");
581+
let val = self.codegen_operand(
582+
tcx, instance, &args[0].node, args[0].node.ty(mir, tcx),
583+
location, mlir_block, state,
584+
)?;
585+
Ok(Some(val))
586+
}
587+
555588
#[allow(clippy::too_many_arguments)]
556589
fn codegen_switch_int<'tcx>(
557590
&self,

0 commit comments

Comments
 (0)