Skip to content

Commit 56d4cd3

Browse files
j2kuncopybara-github
authored andcommitted
distribute-generic: preserve attrs when distributing through scf.if
PiperOrigin-RevId: 908188664
1 parent 0ffb96d commit 56d4cd3

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

lib/Dialect/Secret/Transforms/DistributeGeneric.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ struct SplitGeneric : public OpRewritePattern<GenericOp> {
200200
return failure();
201201
}
202202

203+
newIfOp->setAttrs(opToDistribute->getAttrs());
204+
203205
// Clone the regions
204206
for (int i = 0; i < 2; ++i) {
205207
Region& oldRegion = opToDistribute->getRegion(i);

tests/Dialect/Secret/Transforms/secret_distribute_generic/distribute_generic_if.mlir

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,25 @@ func.func @test_user_example(%arg0: !secret.secret<tensor<1x1024xf32>>, %arg1: !
9999
} -> (!secret.secret<tensor<1x1024xf32>>)
100100
return %0 : !secret.secret<tensor<1x1024xf32>>
101101
}
102+
103+
// -----
104+
105+
// CHECK: @test_distribute_scf_if_with_attr
106+
// CHECK-SAME: %[[arg0:.*]]: !secret.secret<i32>, %[[cond:.*]]: i1
107+
func.func @test_distribute_scf_if_with_attr(%arg0: !secret.secret<i32>, %cond: i1) -> !secret.secret<i32> {
108+
// CHECK: scf.if %[[cond]] -> (!secret.secret<i32>) {
109+
// CHECK: } else {
110+
// CHECK: } {test.attr = "test"}
111+
%0 = secret.generic (%arg0 : !secret.secret<i32>) {
112+
^bb0(%clear_arg0: i32):
113+
%1 = scf.if %cond -> i32 {
114+
%2 = arith.addi %clear_arg0, %clear_arg0 : i32
115+
scf.yield %2 : i32
116+
} else {
117+
%3 = arith.muli %clear_arg0, %clear_arg0 : i32
118+
scf.yield %3 : i32
119+
} {test.attr = "test"}
120+
secret.yield %1 : i32
121+
} -> (!secret.secret<i32>)
122+
return %0 : !secret.secret<i32>
123+
}

0 commit comments

Comments
 (0)