Skip to content

Commit

Permalink
[GVN] Bug fix to reportMayClobberedLoad remark
Browse files Browse the repository at this point in the history
Bug fix to avoid assert crashing when generating remarks for GVN crashing.

Intention of assert is correct but ignores edge case of instructions being equivalent.

Reduced input that causes crash when remarks are turned on:
```
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) {
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
}
```

Reviewed By: fhahn

Differential Revision: https://reviews.llvm.org/D129235
  • Loading branch information
virnarula authored and fhahn committed Jul 7, 2022
1 parent 061df07 commit 89a99ec
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/Scalar/GVN.cpp
Expand Up @@ -1059,8 +1059,8 @@ static void reportMayClobberedLoad(LoadInst *Load, MemDepResult DepInfo,
if (DT->dominates(cast<Instruction>(OtherAccess), cast<Instruction>(U)))
OtherAccess = U;
else
assert(DT->dominates(cast<Instruction>(U),
cast<Instruction>(OtherAccess)));
assert(U == OtherAccess || DT->dominates(cast<Instruction>(U),
cast<Instruction>(OtherAccess)));
} else
OtherAccess = U;
}
Expand Down
21 changes: 21 additions & 0 deletions llvm/test/Transforms/GVN/remarks-selfdomination.ll
@@ -0,0 +1,21 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -gvn -pass-remarks-analysis=gvn -S < %s | FileCheck %s

define ptr @ReplaceWithTidy(ptr %one, ptr %two, ptr %three) {
; CHECK-LABEL: @ReplaceWithTidy(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[TMP0:%.*]] = load ptr, ptr [[ONE:%.*]], align 8
; CHECK-NEXT: store ptr [[TMP0]], ptr [[TMP0]], align 8
; CHECK-NEXT: store ptr null, ptr [[TWO:%.*]], align 8
; CHECK-NEXT: [[TMP1:%.*]] = load ptr, ptr [[TMP0]], align 8
; CHECK-NEXT: store ptr [[TMP1]], ptr [[THREE:%.*]], align 8
; CHECK-NEXT: ret ptr null
;
entry:
%0 = load ptr, ptr %one, align 8
store ptr %0, ptr %0, align 8
store ptr null, ptr %two, align 8
%1 = load ptr, ptr %0, align 8
store ptr %1, ptr %three, align 8
ret ptr null
}

0 comments on commit 89a99ec

Please sign in to comment.