aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2023-05-31 14:53:44 +0200
committerTom Stellard <tstellar@redhat.com>2023-06-01 09:44:36 -0700
commit42f2e6efd84464e2d02f2524b7feecb00efd6ab7 (patch)
tree9842b4352e087a1a966051b899e463c08b5e08af
parent57c54b25929c138b6e933a56a8549a8d59913e75 (diff)
downloadllvm-42f2e6efd84464e2d02f2524b7feecb00efd6ab7.zip
llvm-42f2e6efd84464e2d02f2524b7feecb00efd6ab7.tar.gz
llvm-42f2e6efd84464e2d02f2524b7feecb00efd6ab7.tar.bz2
[AA] Fix comparison of AliasResults (PR63019)
Comparison between two AliasResults implicitly decayed to comparison of AliasResult::Kind. As a result, MergeAliasResults() ended up considering two PartialAlias results with different offsets as equivalent. Fix this by adding an operator== implementation. To stay compatible with extensive use of comparisons between AliasResult and AliasResult::Kind, add an overload for that as well, which will ignore the offset. In the future, it would probably be a good idea to remove these implicit decays to AliasResult::Kind and add dedicated methods to check for specific AliasResult kinds. Fixes https://github.com/llvm/llvm-project/issues/63019. (cherry picked from commit 97f0e7b06e6b76fd85fb81b8c12eba2255ff1742)
-rw-r--r--llvm/include/llvm/Analysis/AliasAnalysis.h9
-rw-r--r--llvm/test/Transforms/GVN/pr63019.ll7
2 files changed, 12 insertions, 4 deletions
diff --git a/llvm/include/llvm/Analysis/AliasAnalysis.h b/llvm/include/llvm/Analysis/AliasAnalysis.h
index 953e15e..8ac6e7d 100644
--- a/llvm/include/llvm/Analysis/AliasAnalysis.h
+++ b/llvm/include/llvm/Analysis/AliasAnalysis.h
@@ -116,6 +116,15 @@ public:
operator Kind() const { return static_cast<Kind>(Alias); }
+ bool operator==(const AliasResult &Other) const {
+ return Alias == Other.Alias && HasOffset == Other.HasOffset &&
+ Offset == Other.Offset;
+ }
+ bool operator!=(const AliasResult &Other) const { return !(*this == Other); }
+
+ bool operator==(Kind K) const { return Alias == K; }
+ bool operator!=(Kind K) const { return !(*this == K); }
+
constexpr bool hasOffset() const { return HasOffset; }
constexpr int32_t getOffset() const {
assert(HasOffset && "No offset!");
diff --git a/llvm/test/Transforms/GVN/pr63019.ll b/llvm/test/Transforms/GVN/pr63019.ll
index cf3a466..f2628a3 100644
--- a/llvm/test/Transforms/GVN/pr63019.ll
+++ b/llvm/test/Transforms/GVN/pr63019.ll
@@ -1,7 +1,7 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
; RUN: opt -S -passes=gvn < %s | FileCheck %s
-; FIXME: This is a miscompile.
+; Make sure the two offsets from the phi don't get merged incorrectly.
define i8 @test(i1 %c, i64 %offset, ptr %ptr) {
; CHECK-LABEL: define i8 @test
; CHECK-SAME: (i1 [[C:%.*]], i64 [[OFFSET:%.*]], ptr [[PTR:%.*]]) {
@@ -18,9 +18,8 @@ define i8 @test(i1 %c, i64 %offset, ptr %ptr) {
; CHECK-NEXT: store i8 0, ptr [[ALLOCA]], align 8
; CHECK-NEXT: [[LOAD1:%.*]] = load i64, ptr [[ALLOCA]], align 8
; CHECK-NEXT: store i64 [[LOAD1]], ptr [[PTR]], align 8
-; CHECK-NEXT: [[TMP0:%.*]] = lshr i64 [[LOAD1]], 16
-; CHECK-NEXT: [[TMP1:%.*]] = trunc i64 [[TMP0]] to i8
-; CHECK-NEXT: ret i8 [[TMP1]]
+; CHECK-NEXT: [[LOAD2:%.*]] = load i8, ptr [[PHI]], align 1
+; CHECK-NEXT: ret i8 [[LOAD2]]
;
start:
%alloca = alloca [8 x i8], align 8