Skip to content

Commit 5a6a9a7

Browse files
authored
[Triton] Fix loop aware CSE not checking op result index (#7338)
Turns out operations can have more than one result.
1 parent cf80141 commit 5a6a9a7

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lib/Dialect/Triton/Transforms/LoopAwareCSE.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ bool LoopCSEDriver::areEqualInLoop(Value a, Value b) {
9393

9494
Operation *aDef = a.getDefiningOp();
9595
Operation *bDef = b.getDefiningOp();
96+
if (cast<OpResult>(a).getResultNumber() !=
97+
cast<OpResult>(b).getResultNumber())
98+
return false;
9699
// For it to be known that the operation results have the same value, they
97100
// must be side effect free.
98101
if (!isMemoryEffectFree(aDef) || !isMemoryEffectFree(bDef))

test/Triton/loop_cse.mlir

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,17 @@ tt.func public @invalid_cache_test(%arg0: i32, %arg1: i32) -> (i32, i32) {
7070
}
7171
tt.return %0#1, %0#3 : i32, i32
7272
}
73+
74+
// CHECK-LABEL: @multiple_op_results
75+
tt.func @multiple_op_results(%arg0: i32) -> (i32, i32) {
76+
%c0_i32 = arith.constant 0 : i32
77+
%c1_i32 = arith.constant 1 : i32
78+
// CHECK: %0:2 = scf.for
79+
%0:2 = scf.for %i = %c0_i32 to %arg0 step %c1_i32 iter_args(%a = %c0_i32, %b = %c0_i32) -> (i32, i32) : i32 {
80+
// CHECK-NEXT: %1:2 = {{.*}} %arg2, %arg3
81+
%1:2 = tt.elementwise_inline_asm "asm" {constraints = "=r,=r,r,r", pure = true, packed_element = 1 : i32} %a, %b : i32, i32 -> i32, i32
82+
// CHECK-NEXT: yield %1#0, %1#1 : i32, i32
83+
scf.yield %1#0, %1#1 : i32, i32
84+
}
85+
tt.return %0#0, %0#1 : i32, i32
86+
}

0 commit comments

Comments
 (0)