Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SeperateConstOffsetFromGEP] Pre-commit tests for or disjoint handling #76972

Merged
merged 1 commit into from
Jan 4, 2024

Conversation

krzysz00
Copy link
Contributor

@krzysz00 krzysz00 commented Jan 4, 2024

  1. Adds tests for the existing interpretation of or as add in SeperateConstOffsetFromGEP.
  2. Pre-commits a test for or disjoint.

1. Adds tests for the existing interpretation of `or` as `add` in
SeperateConstOffsetFromGEP.
2. Pre-commits a test for `or disjoint`.
@llvmbot
Copy link
Collaborator

llvmbot commented Jan 4, 2024

@llvm/pr-subscribers-llvm-transforms

Author: Krzysztof Drewniak (krzysz00)

Changes
  1. Adds tests for the existing interpretation of or as add in SeperateConstOffsetFromGEP.
  2. Pre-commits a test for or disjoint.

Full diff: https://github.com/llvm/llvm-project/pull/76972.diff

1 Files Affected:

  • (added) llvm/test/Transforms/SeparateConstOffsetFromGEP/split-gep-or-as-add.ll (+61)
diff --git a/llvm/test/Transforms/SeparateConstOffsetFromGEP/split-gep-or-as-add.ll b/llvm/test/Transforms/SeparateConstOffsetFromGEP/split-gep-or-as-add.ll
new file mode 100644
index 00000000000000..45154f5a68f92c
--- /dev/null
+++ b/llvm/test/Transforms/SeparateConstOffsetFromGEP/split-gep-or-as-add.ll
@@ -0,0 +1,61 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
+; RUN: opt -S -passes="separate-const-offset-from-gep<lower-gep>" < %s | FileCheck %s
+
+;; Check that or operations, either with operands with no bits in common or that
+;; are disjoint are lowered into constant GEPs. Note that because this is a
+;; target-independent test, the GEP seperator will lower the seperated-off constant
+;; part to ptrtoint-based arithmetic.
+
+define void @testOrDoesntSplit(ptr %p) {
+; CHECK-LABEL: define void @testOrDoesntSplit(
+; CHECK-SAME: ptr [[P:%.*]]) {
+; CHECK-NEXT:    [[VAR:%.*]] = tail call i64 @foo()
+; CHECK-NEXT:    [[OFF:%.*]] = or i64 [[VAR]], 10
+; CHECK-NEXT:    [[Q:%.*]] = getelementptr i8, ptr [[P]], i64 [[OFF]]
+; CHECK-NEXT:    store i8 0, ptr [[Q]], align 1
+; CHECK-NEXT:    ret void
+;
+  %var = tail call i64 @foo()
+  %off = or i64 %var, 10
+  %q = getelementptr i8, ptr %p, i64 %off
+  store i8 0, ptr %q
+  ret void
+}
+
+define void @testNoBitsInCommonOrSplits(ptr %p) {
+; CHECK-LABEL: define void @testNoBitsInCommonOrSplits(
+; CHECK-SAME: ptr [[P:%.*]]) {
+; CHECK-NEXT:    [[VAR:%.*]] = tail call i64 @foo()
+; CHECK-NEXT:    [[VAR_HIGH:%.*]] = and i64 [[VAR]], -16
+; CHECK-NEXT:    [[TMP1:%.*]] = ptrtoint ptr [[P]] to i64
+; CHECK-NEXT:    [[TMP2:%.*]] = add i64 [[TMP1]], [[VAR_HIGH]]
+; CHECK-NEXT:    [[TMP3:%.*]] = add i64 [[TMP2]], 10
+; CHECK-NEXT:    [[TMP4:%.*]] = inttoptr i64 [[TMP3]] to ptr
+; CHECK-NEXT:    store i8 0, ptr [[TMP4]], align 1
+; CHECK-NEXT:    ret void
+;
+  %var = tail call i64 @foo()
+  %var.high = and i64 %var, -16
+  %off = or i64 %var.high, 10
+  %q = getelementptr i8, ptr %p, i64 %off
+  store i8 0, ptr %q
+  ret void
+}
+
+define void @testDisjointOrSplits(ptr %p) {
+; CHECK-LABEL: define void @testDisjointOrSplits(
+; CHECK-SAME: ptr [[P:%.*]]) {
+; CHECK-NEXT:    [[VAR:%.*]] = tail call i64 @foo()
+; CHECK-NEXT:    [[OFF:%.*]] = or disjoint i64 [[VAR]], 10
+; CHECK-NEXT:    [[Q:%.*]] = getelementptr i8, ptr [[P]], i64 [[OFF]]
+; CHECK-NEXT:    store i8 0, ptr [[Q]], align 1
+; CHECK-NEXT:    ret void
+;
+  %var = tail call i64 @foo()
+  %off = or disjoint i64 %var, 10
+  %q = getelementptr i8, ptr %p, i64 %off
+  store i8 0, ptr %q
+  ret void
+}
+
+declare i64 @foo()

@krzysz00 krzysz00 merged commit cd39420 into llvm:main Jan 4, 2024
5 checks passed
krzysz00 added a commit to krzysz00/llvm-project that referenced this pull request Jan 4, 2024
This commit extends separate-const-offset-from-gep to look at the
newly-added `disjoint` flag on `or` instructions so as to preserve
addditional opportunities for optimization.

As with other `or disjoint`-handling commits, this does not remove the
existing check for the or's operands having no bits in common because
`disjoint` is currently not inferred.

The tests were pre-committed in llvm#76972.
krzysz00 added a commit that referenced this pull request Jan 26, 2024
This commit extends separate-const-offset-from-gep to look at the
newly-added `disjoint` flag on `or` instructions so as to preserve
additional opportunities for optimization.

The tests were pre-committed in #76972.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants