diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp --- a/llvm/lib/Transforms/Scalar/GVN.cpp +++ b/llvm/lib/Transforms/Scalar/GVN.cpp @@ -1059,8 +1059,8 @@ if (DT->dominates(cast(OtherAccess), cast(U))) OtherAccess = U; else - assert(DT->dominates(cast(U), - cast(OtherAccess))); + assert(U == OtherAccess || DT->dominates(cast(U), + cast(OtherAccess))); } else OtherAccess = U; } diff --git a/llvm/test/Transforms/GVN/remarks-selfdomination.ll b/llvm/test/Transforms/GVN/remarks-selfdomination.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Transforms/GVN/remarks-selfdomination.ll @@ -0,0 +1,24 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt -gvn -pass-remarks-analysis=gvn -S < %s | FileCheck %s + +target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128" +target triple = "arm64-apple-macosx12.0.0" + +define ptr @ReplaceWithTidy(ptr %zz_hold) { +; CHECK-LABEL: @ReplaceWithTidy( +; CHECK-NEXT: cond.end480.us: +; CHECK-NEXT: [[TMP0:%.*]] = load ptr, ptr null, align 8 +; CHECK-NEXT: store ptr [[TMP0]], ptr [[TMP0]], align 8 +; CHECK-NEXT: store ptr null, ptr [[ZZ_HOLD:%.*]], align 8 +; CHECK-NEXT: [[TMP1:%.*]] = load ptr, ptr [[TMP0]], align 8 +; CHECK-NEXT: store ptr [[TMP1]], ptr null, align 8 +; CHECK-NEXT: ret ptr null +; +cond.end480.us: + %0 = load ptr, ptr null, align 8 + store ptr %0, ptr %0, align 8 + store ptr null, ptr %zz_hold, align 8 + %1 = load ptr, ptr %0, align 8 + store ptr %1, ptr null, align 8 + ret ptr null +}