diff options
author | DianQK <dianqk@dianqk.net> | 2024-08-04 16:45:10 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-04 16:45:10 +0800 |
commit | 4377656f2419a8eb18c01e86929b689dcf22b5d6 (patch) | |
tree | 0371cd311652d06d70254d2c6a342fbd0ea24a97 | |
parent | eccc6487c1fc5925ea2e595b5b07a31976c3232e (diff) | |
download | llvm-4377656f2419a8eb18c01e86929b689dcf22b5d6.zip llvm-4377656f2419a8eb18c01e86929b689dcf22b5d6.tar.gz llvm-4377656f2419a8eb18c01e86929b689dcf22b5d6.tar.bz2 |
[Metadata] Try to merge the first and last ranges. (#101860)
Fixes #101859.
If we have at least 2 ranges, we have to try to merge the last and first
ones to handle the wrap range.
-rw-r--r-- | llvm/lib/IR/Metadata.cpp | 5 | ||||
-rw-r--r-- | llvm/test/Transforms/GVN/merge-range.ll | 20 |
2 files changed, 23 insertions, 2 deletions
diff --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp index ae5f5de1..fd2f4d1 100644 --- a/llvm/lib/IR/Metadata.cpp +++ b/llvm/lib/IR/Metadata.cpp @@ -1318,10 +1318,11 @@ MDNode *MDNode::getMostGenericRange(MDNode *A, MDNode *B) { ++BI; } - // If we have more than 2 ranges (4 endpoints) we have to try to merge + // We haven't handled wrap in the previous merge, + // if we have at least 2 ranges (4 endpoints) we have to try to merge // the last and first ones. unsigned Size = EndPoints.size(); - if (Size > 4) { + if (Size > 2) { ConstantInt *FB = EndPoints[0]; ConstantInt *FE = EndPoints[1]; if (tryMergeRange(EndPoints, FB, FE)) { diff --git a/llvm/test/Transforms/GVN/merge-range.ll b/llvm/test/Transforms/GVN/merge-range.ll new file mode 100644 index 0000000..ad1fa4c --- /dev/null +++ b/llvm/test/Transforms/GVN/merge-range.ll @@ -0,0 +1,20 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 +; RUN: opt -passes=gvn -S < %s | FileCheck %s + +define i8 @foo(ptr %arg, i8 %arg1) { +; CHECK-LABEL: define i8 @foo( +; CHECK-SAME: ptr [[ARG:%.*]], i8 [[ARG1:%.*]]) { +; CHECK-NEXT: [[BB:.*:]] +; CHECK-NEXT: [[I:%.*]] = load i8, ptr [[ARG]], align 1, !range [[RNG0:![0-9]+]] +; CHECK-NEXT: [[I3:%.*]] = add i8 [[I]], [[I]] +; CHECK-NEXT: ret i8 [[I3]] +; +bb: + %i = load i8, ptr %arg, align 1, !range !{i8 127, i8 -20} + %i2 = load i8, ptr %arg, align 1, !range !{i8 -27, i8 -24, i8 -20, i8 -17} + %i3 = add i8 %i, %i2 + ret i8 %i3 +} +;. +; CHECK: [[RNG0]] = !{i8 127, i8 -17} +;. |