Skip to content

Commit be61781

Browse files
authored
1 parent 6b92cce commit be61781

File tree

7 files changed

+155
-119
lines changed

7 files changed

+155
-119
lines changed

WORKSPACE.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ workspace(name = "stablehlo")
1717

1818
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
1919

20-
LLVM_COMMIT = "fc44a4fcd3c54be927c15ddd9211aca1501633e7"
20+
LLVM_COMMIT = "cb2f0d0a5f14c183e7182aba0f0e54a518de9e3f"
2121

22-
LLVM_SHA256 = "d228aebe5583c69c4e48fd7a8e149e3d22ee6dafaeae94009467143d32d9bfc4"
22+
LLVM_SHA256 = "e8ece380fdb57dc6f8e42df9db872a1ade5056c5379075e3e2f99c89200aea69"
2323

2424
http_archive(
2525
name = "llvm-raw",

build_tools/llvm_version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
fc44a4fcd3c54be927c15ddd9211aca1501633e7
1+
cb2f0d0a5f14c183e7182aba0f0e54a518de9e3f

stablehlo/dialect/StablehloOps.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ LogicalResult CustomCallOp::verify() {
542542
// to allow erroring in StableHLO for these custom calls.
543543
LogicalResult CustomCallOp::verifyKnownCustomCalls() {
544544
// We have already verified that the output_operand_aliases have consistent
545-
// types and valid indices. Here we verify buffer releated special custom_call
545+
// types and valid indices. Here we verify buffer-related special custom_call
546546
// targets, and also verify that buffer operands used non-special custom_call
547547
// ops meet this requirements:
548548
// A result with a buffer type should be mentioned in one pair of

stablehlo/tests/transforms/stablehlo_aggressive_simplification.mlir

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,17 +1633,17 @@ func.func @select_into_minmax1(%arg0: tensor<2xi32>, %arg1: tensor<2xi32>,
16331633
%s4 = stablehlo.select %4, %arg1, %arg2 : (tensor<2xi1>, tensor<2xi32>, tensor<2xi32>) -> tensor<2xi32>
16341634
%s5 = stablehlo.select %5, %arg1, %arg3 : (tensor<2xi1>, tensor<2xi32>, tensor<2xi32>) -> tensor<2xi32>
16351635

1636-
// CHECK-DAG: [[C0:%.+]] = stablehlo.compare EQ, [[ARG0]], [[ARG1]], SIGNED
1637-
// CHECK-DAG: [[C1:%.+]] = stablehlo.compare NE, [[ARG0]], [[ARG1]], SIGNED
1636+
// DISABLED-CHECK-DAG: [[C0:%.+]] = stablehlo.compare EQ, [[ARG0]], [[ARG1]], SIGNED
1637+
// DISABLED-CHECK-DAG: [[C1:%.+]] = stablehlo.compare NE, [[ARG0]], [[ARG1]], SIGNED
16381638

1639-
// CHECK-DAG: [[S0:%.+]] = stablehlo.select [[C0]], [[ARG0]], [[ARG1]]
1640-
// CHECK-DAG: [[S1:%.+]] = stablehlo.select [[C1]], [[ARG0]], [[ARG1]]
1641-
// CHECK-DAG: [[S2:%.+]] = stablehlo.maximum [[ARG0]], [[ARG1]]
1642-
// CHECK-DAG: [[S3:%.+]] = stablehlo.maximum [[ARG0]], [[ARG2]]
1643-
// CHECK-DAG: [[S4:%.+]] = stablehlo.minimum [[ARG1]], [[ARG2]]
1644-
// CHECK-DAG: [[S5:%.+]] = stablehlo.minimum [[ARG1]], [[ARG3]]
1639+
// DISABLED-CHECK-DAG: [[S0:%.+]] = stablehlo.select [[C0]], [[ARG0]], [[ARG1]]
1640+
// DISABLED-CHECK-DAG: [[S1:%.+]] = stablehlo.select [[C1]], [[ARG0]], [[ARG1]]
1641+
// DISABLED-CHECK-DAG: [[S2:%.+]] = stablehlo.maximum [[ARG0]], [[ARG1]]
1642+
// DISABLED-CHECK-DAG: [[S3:%.+]] = stablehlo.maximum [[ARG0]], [[ARG2]]
1643+
// DISABLED-CHECK-DAG: [[S4:%.+]] = stablehlo.minimum [[ARG1]], [[ARG2]]
1644+
// DISABLED-CHECK-DAG: [[S5:%.+]] = stablehlo.minimum [[ARG1]], [[ARG3]]
16451645

1646-
// CHECK-NEXT: return [[S0]], [[S1]], [[S2]], [[S3]], [[S4]], [[S5]]
1646+
// DISABLED-CHECK-NEXT: return [[S0]], [[S1]], [[S2]], [[S3]], [[S4]], [[S5]]
16471647
return %s0, %s1, %s2, %s3, %s4, %s5 :
16481648
tensor<2xi32>, tensor<2xi32>, tensor<2xi32>, tensor<2xi32>, tensor<2xi32>, tensor<2xi32>
16491649
}
@@ -1674,23 +1674,23 @@ func.func @select_into_minmax2(%arg0: tensor<i32>, %arg1: tensor<i32>, %arg2: te
16741674
%s6 = stablehlo.select %6, %arg3, %arg2 : (tensor<i1>, tensor<i32>, tensor<i32>) -> tensor<i32>
16751675
%s7 = stablehlo.select %7, %arg2, %arg3 : (tensor<i1>, tensor<i32>, tensor<i32>) -> tensor<i32>
16761676

1677-
// CHECK-DAG: [[C1:%.+]] = stablehlo.compare GT, [[ARG1]], [[ARG2]], SIGNED
1678-
// CHECK-DAG: [[C3:%.+]] = stablehlo.compare GE, [[ARG1]], [[ARG2]], SIGNED
1677+
// DISABLED-CHECK-DAG: [[C1:%.+]] = stablehlo.compare GT, [[ARG1]], [[ARG2]], SIGNED
1678+
// DISABLED-CHECK-DAG: [[C3:%.+]] = stablehlo.compare GE, [[ARG1]], [[ARG2]], SIGNED
16791679

1680-
// CHECK-DAG: [[S0:%.+]] = stablehlo.minimum [[ARG0]], [[ARG1]]
1681-
// CHECK-DAG: [[S1:%.+]] = stablehlo.select [[C1]], [[ARG0]], [[ARG1]]
1682-
// CHECK-DAG: [[S2:%.+]] = stablehlo.minimum [[ARG3]], [[ARG1]]
1683-
// CHECK-DAG: [[S3:%.+]] = stablehlo.select [[C3]], [[ARG0]], [[ARG2]]
1680+
// DISABLED-CHECK-DAG: [[S0:%.+]] = stablehlo.minimum [[ARG0]], [[ARG1]]
1681+
// DISABLED-CHECK-DAG: [[S1:%.+]] = stablehlo.select [[C1]], [[ARG0]], [[ARG1]]
1682+
// DISABLED-CHECK-DAG: [[S2:%.+]] = stablehlo.minimum [[ARG3]], [[ARG1]]
1683+
// DISABLED-CHECK-DAG: [[S3:%.+]] = stablehlo.select [[C3]], [[ARG0]], [[ARG2]]
16841684

1685-
// CHECK-DAG: [[C5:%.+]] = stablehlo.compare LT, [[ARG0]], [[ARG2]], SIGNED
1686-
// CHECK-DAG: [[C7:%.+]] = stablehlo.compare LE, [[ARG0]], [[ARG2]], SIGNED
1685+
// DISABLED-CHECK-DAG: [[C5:%.+]] = stablehlo.compare LT, [[ARG0]], [[ARG2]], SIGNED
1686+
// DISABLED-CHECK-DAG: [[C7:%.+]] = stablehlo.compare LE, [[ARG0]], [[ARG2]], SIGNED
16871687

1688-
// CHECK-DAG: [[S4:%.+]] = stablehlo.maximum [[ARG2]], [[ARG1]]
1689-
// CHECK-DAG: [[S5:%.+]] = stablehlo.select [[C5]], [[ARG1]], [[ARG2]]
1690-
// CHECK-DAG: [[S6:%.+]] = stablehlo.maximum [[ARG3]], [[ARG2]]
1691-
// CHECK-DAG: [[S7:%.+]] = stablehlo.select [[C7]], [[ARG2]], [[ARG3]]
1688+
// DISABLED-CHECK-DAG: [[S4:%.+]] = stablehlo.maximum [[ARG2]], [[ARG1]]
1689+
// DISABLED-CHECK-DAG: [[S5:%.+]] = stablehlo.select [[C5]], [[ARG1]], [[ARG2]]
1690+
// DISABLED-CHECK-DAG: [[S6:%.+]] = stablehlo.maximum [[ARG3]], [[ARG2]]
1691+
// DISABLED-CHECK-DAG: [[S7:%.+]] = stablehlo.select [[C7]], [[ARG2]], [[ARG3]]
16921692

1693-
// CHECK-NEXT: return [[S0]], [[S1]], [[S2]], [[S3]], [[S4]], [[S5]], [[S6]], [[S7]]
1693+
// DISABLED-CHECK-NEXT: return [[S0]], [[S1]], [[S2]], [[S3]], [[S4]], [[S5]], [[S6]], [[S7]]
16941694
return %s0, %s1, %s2, %s3, %s4, %s5, %s6, %s7 : tensor<i32>, tensor<i32>, tensor<i32>, tensor<i32>,
16951695
tensor<i32>, tensor<i32>, tensor<i32>, tensor<i32>
16961696
}
@@ -2040,12 +2040,12 @@ func.func @side_effecting_custom_call(%arg0: tensor<0xf32>) -> (tensor<0xf32>, t
20402040

20412041
// CHECK-LABEL: @push_shape_ops_to_end
20422042
func.func @push_shape_ops_to_end(%arg0 : tensor<12xf32>) -> tensor<3x4x2x1xf32> {
2043-
// CHECK: %[[COS:.+]] = stablehlo.cosine %arg0 : tensor<12xf32>
2044-
// CHECK: %[[ABS:.+]] = stablehlo.abs %[[COS]] : tensor<12xf32>
2045-
// CHECK: %[[RESHAPE:.+]] = stablehlo.reshape %[[ABS]] : (tensor<12xf32>) -> tensor<3x4xf32>
2046-
// CHECK: %[[BROADCAST:.+]] = stablehlo.broadcast %[[RESHAPE]], sizes = [1, 2] : (tensor<3x4xf32>) -> tensor<1x2x3x4xf32>
2047-
// CHECK: %[[TRANSPOSE:.+]] = stablehlo.transpose %[[BROADCAST]], dims = [2, 3, 1, 0] : (tensor<1x2x3x4xf32>) -> tensor<3x4x2x1xf32>
2048-
// CHECK: return %[[TRANSPOSE]]
2043+
// DISABLED-CHECK: %[[COS:.+]] = stablehlo.cosine %arg0 : tensor<12xf32>
2044+
// DISABLED-CHECK: %[[ABS:.+]] = stablehlo.abs %[[COS]] : tensor<12xf32>
2045+
// DISABLED-CHECK: %[[RESHAPE:.+]] = stablehlo.reshape %[[ABS]] : (tensor<12xf32>) -> tensor<3x4xf32>
2046+
// DISABLED-CHECK: %[[BROADCAST:.+]] = stablehlo.broadcast %[[RESHAPE]], sizes = [1, 2] : (tensor<3x4xf32>) -> tensor<1x2x3x4xf32>
2047+
// DISABLED-CHECK: %[[TRANSPOSE:.+]] = stablehlo.transpose %[[BROADCAST]], dims = [2, 3, 1, 0] : (tensor<1x2x3x4xf32>) -> tensor<3x4x2x1xf32>
2048+
// DISABLED-CHECK: return %[[TRANSPOSE]]
20492049
%0 = stablehlo.reshape %arg0 : (tensor<12xf32>) -> tensor<3x4xf32>
20502050
%1 = stablehlo.broadcast %0, sizes = [1, 2] : (tensor<3x4xf32>) -> tensor<1x2x3x4xf32>
20512051
%2 = stablehlo.cosine %1 : (tensor<1x2x3x4xf32>) -> tensor<1x2x3x4xf32>
@@ -2059,9 +2059,9 @@ func.func @push_shape_ops_to_end(%arg0 : tensor<12xf32>) -> tensor<3x4x2x1xf32>
20592059

20602060
// CHECK-LABEL: @reorder_with_type_change
20612061
func.func @reorder_with_type_change(%arg0 : tensor<3x4xi32>) -> tensor<12xi64> {
2062-
// CHECK: %[[CONVERT:.+]] = stablehlo.convert %arg0 : (tensor<3x4xi32>) -> tensor<3x4xi64>
2063-
// CHECK: %[[RESHAPE:.+]] = stablehlo.reshape %[[CONVERT]] : (tensor<3x4xi64>) -> tensor<12xi64>
2064-
// CHECK: return %[[RESHAPE]]
2062+
// DISABLED-CHECK: %[[CONVERT:.+]] = stablehlo.convert %arg0 : (tensor<3x4xi32>) -> tensor<3x4xi64>
2063+
// DISABLED-CHECK: %[[RESHAPE:.+]] = stablehlo.reshape %[[CONVERT]] : (tensor<3x4xi64>) -> tensor<12xi64>
2064+
// DISABLED-CHECK: return %[[RESHAPE]]
20652065
%0 = stablehlo.reshape %arg0 : (tensor<3x4xi32>) -> tensor<12xi32>
20662066
%1 = stablehlo.convert %0 : (tensor<12xi32>) -> tensor<12xi64>
20672067
return %1 : tensor<12xi64>

stablehlo/tests/transforms/stablehlo_target_independent_optimization.mlir

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,34 @@ func.func @dce_while_false_condition(%arg0: tensor<i64>) -> tensor<i64> {
5959
}
6060
return %0 : tensor<i64>
6161
}
62+
63+
// -----
64+
65+
// Check that we properly handle expressions involving NaN terms or variables
66+
// that could potentially be NaN.
67+
68+
// CHECK-LABEL: @fold_constant_nan_to_nan
69+
func.func @fold_constant_nan_to_nan() -> tensor<f32> {
70+
// CHECK: [[NAN:%.*]] = stablehlo.constant dense<0x7FC00000> : tensor<f32>
71+
// CHECK: return [[NAN]] : tensor<f32>
72+
%zero = stablehlo.constant dense<0.0> : tensor<f32>
73+
%one = stablehlo.constant dense<1.0> : tensor<f32>
74+
%nan = stablehlo.constant dense<0x7FC00000> : tensor<f32>
75+
%nan_times_zero = stablehlo.multiply %nan, %zero : tensor<f32>
76+
%result = stablehlo.add %one, %nan_times_zero : tensor<f32>
77+
return %result : tensor<f32>
78+
}
79+
80+
// TODO: Consider adding an `--assume-non-nan` pass option to override this.
81+
// CHECK-LABEL: @do_not_assume_non_nan
82+
func.func @do_not_assume_non_nan(%arg0: tensor<f32>) -> tensor<f32> {
83+
// Note: These two checks are out of order on purpose: [[RESULT]] binds to the
84+
// `return` op first and then looks backward for the corresponding assignment.
85+
// CHECK-DAG: return [[RESULT:.*]] : tensor<f32>
86+
// CHECK-DAG: [[RESULT]] = stablehlo.{{(add|multiply).*}} : tensor<f32>
87+
%zero = stablehlo.constant dense<0.0> : tensor<f32>
88+
%one = stablehlo.constant dense<1.0> : tensor<f32>
89+
%arg_times_zero = stablehlo.multiply %arg0, %zero : tensor<f32>
90+
%result = stablehlo.add %one, %arg_times_zero : tensor<f32>
91+
return %result : tensor<f32>
92+
}

0 commit comments

Comments
 (0)