Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ struct RewriteEnv {
}

/// Records both ways in which later rewriting must understand an original
/// value. oldValue is the key from the original IR, info is its
/// component descriptor, and rebuiltValue is the pointer-like SSA value
/// created in the replacement IR. Pointer-aware code reads info from
/// decomposedValues; ordinary cloned users read rebuiltValue through
/// value. oldValue is the key from the original IR, info is its component
/// descriptor, and rebuiltValue is the pointer-like SSA value created in the
/// replacement IR. Pointer-aware code may encounter either SSA value, so
/// both keys resolve to info; ordinary cloned users read rebuiltValue through
/// valueMapping.
///
/// For example, after rebuilding an expanded loop argument:
Expand All @@ -189,13 +189,19 @@ struct RewriteEnv {
void recordDecomposition(Value oldValue, const DecomposedValue &info,
Value rebuiltValue) {
decomposedValues[oldValue] = info;
// A later cloned operation may consume the rebuilt value directly rather
// than the original value. Cache the same descriptor under that SSA value
// so chained pointer producers reuse the existing decomposition instead
// of re-materializing branch-local components.
decomposedValues[rebuiltValue] = info;
valueMapping.map(oldValue, rebuiltValue);
}

// Maps values from the original region to values in the replacement region.
IRMapping valueMapping;
// Concrete component state keyed by original values. Keeping this alongside
// the mapping lets pointer producers be flattened across nested rewrites.
// Concrete component state keyed by original and rebuilt pointer values.
// Keeping this alongside the mapping lets chained pointer producers and
// nested rewrites reuse an already materialized descriptor.
DenseMap<Value, DecomposedValue> decomposedValues;
const ControlFlowRewritePolicy &policy;
const ControlFlowRewritePlan &plan;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,44 @@ module {

// -----

module {
tt.func public @if_tensor_ptr_same_base_chained_addptr(
%base: !tt.ptr<f32>, %output: !tt.ptr<f32>, %cond: i1) {
%then_offset = arith.constant dense<2> : tensor<16xi32>
%else_offset = arith.constant dense<5> : tensor<16xi32>
%lane = tt.make_range {end = 16 : i32, start = 0 : i32}
%selected = scf.if %cond -> (tensor<16x!tt.ptr<f32>>) {
%base_tensor = tt.splat %base : !tt.ptr<f32> -> tensor<16x!tt.ptr<f32>>
%lane_ptr = tt.addptr %base_tensor, %lane : tensor<16x!tt.ptr<f32>>, tensor<16xi32>
%then_ptr = tt.addptr %lane_ptr, %then_offset : tensor<16x!tt.ptr<f32>>, tensor<16xi32>
scf.yield %then_ptr : tensor<16x!tt.ptr<f32>>
} else {
%base_tensor = tt.splat %base : !tt.ptr<f32> -> tensor<16x!tt.ptr<f32>>
%lane_ptr = tt.addptr %base_tensor, %lane : tensor<16x!tt.ptr<f32>>, tensor<16xi32>
%else_ptr = tt.addptr %lane_ptr, %else_offset : tensor<16x!tt.ptr<f32>>, tensor<16xi32>
scf.yield %else_ptr : tensor<16x!tt.ptr<f32>>
}
%output_tensor = tt.splat %output : !tt.ptr<f32> -> tensor<16x!tt.ptr<f32>>
%output_ptr = tt.addptr %output_tensor, %lane : tensor<16x!tt.ptr<f32>>, tensor<16xi32>
%loaded = tt.load %selected : tensor<16x!tt.ptr<f32>>
tt.store %output_ptr, %loaded : tensor<16x!tt.ptr<f32>>
tt.return
}
}

// CHECK-LABEL: tt.func public @if_tensor_ptr_same_base_chained_addptr
// CHECK: %[[CHAINED_OFF:.*]] = scf.if %{{.*}} -> (i32) {
// CHECK: scf.yield %{{.*}} : i32
// CHECK: } else {
// CHECK: scf.yield %{{.*}} : i32
// CHECK: }
// CHECK: %[[CHAINED_PTR:.*]] = tt.addptr
// CHECK-SAME: PointerDescriptorOffsetForm = "strided_1d"
// CHECK-SAME: PointerDescriptorRebuild
// CHECK: tt.load %[[CHAINED_PTR]] : tensor<16x!tt.ptr<f32>>

// -----

module {
tt.func public @while_block_ptr_large_step(%base: !tt.ptr<f16>, %n: i32) -> !tt.ptr<tensor<32xf16>> {
%c0_i32 = arith.constant 0 : i32
Expand Down
Loading