-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[GlobalISel] Add G_ABS computeKnownBits #154413
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
base: main
Are you sure you want to change the base?
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-backend-aarch64 @llvm/pr-subscribers-llvm-globalisel Author: Pragyansh Chaturvedi (r41k0u) ChangesThe code is taken from Full diff: https://github.com/llvm/llvm-project/pull/154413.diff 1 Files Affected:
diff --git a/llvm/lib/CodeGen/GlobalISel/GISelValueTracking.cpp b/llvm/lib/CodeGen/GlobalISel/GISelValueTracking.cpp
index 974fc40de6222..df1b325fa5baf 100644
--- a/llvm/lib/CodeGen/GlobalISel/GISelValueTracking.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/GISelValueTracking.cpp
@@ -697,6 +697,14 @@ void GISelValueTracking::computeKnownBitsImpl(Register R, KnownBits &Known,
}
break;
}
+ case TargetOpcode::G_ABS: {
+ Register SrcReg = MI.getOperand(1).getReg();
+ computeKnownBitsImpl(SrcReg, Known, DemandedElts, Depth + 1);
+ Known = Known.abs();
+ Known.Zero.setHighBits(computeNumSignBits(SrcReg, DemandedElts, Depth + 1) -
+ 1);
+ break;
+ }
}
LLVM_DEBUG(dumpResult(MI, Known, Depth));
|
I ran the tests and found no new regressions. I am not sure how to add tests for this (as I saw in other PRs attached to the issue). I came across |
The output is generated, the input is not. That's a new style to directly check the output. The older style is to write the simplest code that will optimize or not based on the analysis
https://llvm.org/docs/TestingGuide.html#generating-assertions-in-regression-tests You're probably best off copy-pasting one of the tests from the recent GIValueTracking commits as a starting point |
Hi @davemgreen, I've added a couple of tests for this. Please lmk if more of them are needed. |
; CHECK-NEXT: %1:_ KnownBits:00010010 SignBits:3 | ||
%0:_(s8) = G_CONSTANT i8 238 | ||
%1:_(s8) = G_ABS %0 | ||
... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also check G_ABS of G_IMPLICIT_DEF, and a vector splat and non-splat case
@@ -0,0 +1,23 @@ | |||
# NOTE: Assertions have been autogenerated by utils/update_givaluetracking_test_checks.py UTC_ARGS: --version 5 | |||
# RUN: llc -mtriple aarch64 -passes="print<gisel-value-tracking>" %s -filetype=null 2>&1 | FileCheck %s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# RUN: llc -mtriple aarch64 -passes="print<gisel-value-tracking>" %s -filetype=null 2>&1 | FileCheck %s | |
# RUN: llc -mtriple=aarch64 -passes='print<gisel-value-tracking>' -filetype=null %s 2>&1 | FileCheck %s |
The code is taken from
SelectionDAG::computeKnownBits
.This ticks off ABS from #150515