diff --git a/taichi/analysis/alias_analysis.cpp b/taichi/analysis/alias_analysis.cpp index e530b8a252697..e364f1f23175f 100644 --- a/taichi/analysis/alias_analysis.cpp +++ b/taichi/analysis/alias_analysis.cpp @@ -99,8 +99,12 @@ AliasResult alias_analysis(Stmt *var1, Stmt *var2) { return AliasResult::different; auto ptr1 = var1->as(); auto ptr2 = var2->as(); - if (ptr1->base_ptrs[0] != ptr2->base_ptrs[0]) - return AliasResult::uncertain; + if (ptr1->base_ptrs[0] != ptr2->base_ptrs[0]) { + auto base1 = ptr1->base_ptrs[0]->as(); + auto base2 = ptr2->base_ptrs[0]->as(); + return base1->arg_id != base2->arg_id ? AliasResult::different + : AliasResult::uncertain; + } TI_ASSERT(ptr1->indices.size() == ptr2->indices.size()); bool uncertain = false; for (int i = 0; i < (int)ptr1->indices.size(); i++) { diff --git a/tests/cpp/analysis/alias_analysis_test.cpp b/tests/cpp/analysis/alias_analysis_test.cpp index 3ca8534785d95..ac6dfd4492b90 100644 --- a/tests/cpp/analysis/alias_analysis_test.cpp +++ b/tests/cpp/analysis/alias_analysis_test.cpp @@ -143,7 +143,7 @@ TEST(AliasAnalysis, ExternalPtr_DiffPtr) { auto *eptr2 = builder.create_external_ptr(arg2, indices); const auto aa = alias_analysis(eptr1, eptr2); - EXPECT_EQ(aa, AliasResult::uncertain); + EXPECT_EQ(aa, AliasResult::different); } } // namespace analysis