Fix an incorrect precondition check in IndexedArrayAnalysis
authorSanjoy Das <sanjoy@google.com>
Tue, 29 May 2018 06:55:19 +0000 (23:55 -0700)
committerTensorFlower Gardener <gardener@tensorflow.org>
Tue, 29 May 2018 06:57:57 +0000 (23:57 -0700)
PiperOrigin-RevId: 198354001

tensorflow/compiler/xla/service/indexed_array_analysis.cc
tensorflow/compiler/xla/service/indexed_array_analysis_test.cc

index 11d931c..8b3fa6c 100644 (file)
@@ -689,7 +689,7 @@ IndexedArrayAnalysis::ComputeArrayForElementwiseUnaryOp(HloOpcode opcode,
                                                         Array* operand) {
   auto* scalar_indexed_const =
       dynamic_cast<ScalarIndexedConstantArray*>(operand);
-  if (operand == nullptr) {
+  if (scalar_indexed_const == nullptr) {
     return nullptr;
   }
 
index 68f247b..373556e 100644 (file)
@@ -472,5 +472,33 @@ ENTRY main {
 
   AssertArrayForRootExpressionIs(hlo_text, "%add");
 }
+
+TEST_F(IndexedArrayAnalysisTest, RegularUnaryOp) {
+  string hlo_text = R"(
+HloModule RegularUnaryOp
+
+ENTRY main {
+  input = f32[100] parameter(0)
+  ROOT tanh = f32[100] tanh(input)
+}
+)";
+
+  AssertArrayForRootExpressionIs(hlo_text, "%tanh");
+}
+
+TEST_F(IndexedArrayAnalysisTest, RegularBinaryOp) {
+  string hlo_text = R"(
+HloModule RegularUnaryOp
+
+ENTRY main {
+  input0 = f32[100] parameter(0)
+  input1 = f32[100] parameter(1)
+  ROOT add = f32[100] add(input0, input1)
+}
+)";
+
+  AssertArrayForRootExpressionIs(hlo_text, "%add");
+}
+
 }  // namespace
 }  // namespace xla