X86: Add pattern for optimized BLSIC IR form#209814
Conversation
|
Hello @Logans-olo 👋 Thank you for submitting a Pull Request (PR) to the LLVM Project. Since this is your first PR, here are a few useful links covering our main contribution policies and review practices.
Please reply to this message to confirm that you have read these policies, especially the LLVM AI Tool Use Policy, and that any AI tool usage has been noted in the PR description. Frequently asked questionsHow do I add reviewers? This PR will be automatically labeled, and the relevant teams will be notified. For some parts of the project, reviewers may also be added automatically. You can also add reviewers manually using the Reviewers section on this page. If you cannot use that section, it is probably because you do not have write permissions for the repository. In that case, you can request a review by tagging reviewers in a comment using What if there are no comments? If you have not received any comments on your PR after a week, you can request a review by pinging the PR with a comment such as “Ping”. The common courtesy ping rate is once a week. Please remember that you are asking for volunteer time from other developers. Are any special GitHub settings required to contribute to LLVM? We only require contributors to have a public email address associated with their GitHub commits, see this section of LLVM Developer Policy for details. If you have questions, feel free to leave a comment on this PR, or ask on LLVM Discord or LLVM Discourse. Thank you, |
|
@llvm/pr-subscribers-llvm-binary-utilities @llvm/pr-subscribers-backend-x86 Author: Logan (Logans-olo) ChangesAdd DAG pattern to recognize the optimized IR form of BLSIC: This matches the IR form produced after InstCombine optimizations, fixing code generation regression from issue #209718. Added tests for both 32-bit and 64-bit BLSIC patterns 2 Files Affected:
diff --git a/llvm/lib/Target/X86/X86InstrTBM.td b/llvm/lib/Target/X86/X86InstrTBM.td
index 09200f0c1a9f6..a324925dc46cb 100644
--- a/llvm/lib/Target/X86/X86InstrTBM.td
+++ b/llvm/lib/Target/X86/X86InstrTBM.td
@@ -125,6 +125,11 @@ let Predicates = [HasTBM] in {
def : Pat<(or GR64:$src, (add GR64:$src, -1)),
(BLSFILL64rr GR64:$src)>;
+ def : Pat<(xor (and GR32:$src, (sub 0, GR32:$src)), -1),
+ (BLSIC32rr GR32:$src)>;
+ def : Pat<(xor (and GR64:$src, (sub 0, GR64:$src)), -1),
+ (BLSIC64rr GR64:$src)>;
+
def : Pat<(or (not GR32:$src), (add GR32:$src, -1)),
(BLSIC32rr GR32:$src)>;
def : Pat<(or (not GR64:$src), (add GR64:$src, -1)),
diff --git a/llvm/test/CodeGen/X86/tbm-blsic-patterns.ll b/llvm/test/CodeGen/X86/tbm-blsic-patterns.ll
new file mode 100644
index 0000000000000..98370869c5073
--- /dev/null
+++ b/llvm/test/CodeGen/X86/tbm-blsic-patterns.ll
@@ -0,0 +1,40 @@
+; RUN: llc -mattr=+tbm < %s | FileCheck %s
+
+target triple = "x86_64-unknown-linux-gnu"
+
+; CHECK-LABEL: test_blsic_original
+; CHECK: blsicl
+define i32 @test_blsic_original(i32 %x) {
+ %_2 = xor i32 %x, -1
+ %_0.i = add i32 %x, -1
+ %_0 = or i32 %_0.i, %_2
+ ret i32 %_0
+}
+
+; CHECK-LABEL: test_blsic_optimized
+; CHECK: blsicl
+define i32 @test_blsic_optimized(i32 %x) {
+ %1 = sub i32 0, %x
+ %2 = and i32 %x, %1
+ %3 = xor i32 %2, -1
+ ret i32 %3
+}
+
+; 64-bit versions
+; CHECK-LABEL: test_blsic_64_original
+; CHECK: blsicq
+define i64 @test_blsic_64_original(i64 %x) {
+ %_2 = xor i64 %x, -1
+ %_0.i = add i64 %x, -1
+ %_0 = or i64 %_0.i, %_2
+ ret i64 %_0
+}
+
+; CHECK-LABEL: test_blsic_64_optimized
+; CHECK: blsicq
+define i64 @test_blsic_64_optimized(i64 %x) {
+ %1 = sub i64 0, %x
+ %2 = and i64 %x, %1
+ %3 = xor i64 %2, -1
+ ret i64 %3
+}
|
RKSimon
left a comment
There was a problem hiding this comment.
don't add a new test file - just add the additional tests to tbm_patterns.ll close to the original blsic tests - and make sure you use the update script
cdc482d to
27cc3c1
Compare
RKSimon
left a comment
There was a problem hiding this comment.
regenerate the test file with the update script
e464016 to
9806a24
Compare
|
Thank you for the review, the changes should be resolved now. Maybe it is a me problem, but why is the update branch option still available? For example, I just rebased using the Github UI, but the option is still there. Is there something I should do from CLI? Thank you again, and sorry to be such a pain. |
9806a24 to
02003d2
Compare
Nevermind, seems I just got unlucky, and needed to do it again |
🪟 Windows x64 Test Results
✅ The build succeeded and all tests passed. |
02003d2 to
a9f1362
Compare
19a0a73 to
9173236
Compare
4da0175 to
4055107
Compare
Add DAG pattern to recognize the optimized IR form of BLSIC: (xor (and x, -x), -1) This matches the IR form produced after InstCombine optimizations, fixing code generation regression from issue llvm#209718.
…te test block labels to pass.
4055107 to
01e4c61
Compare
01e4c61 to
6e8fe6e
Compare
…iling whitespace and remove sub in favor of ineg
6e8fe6e to
d0d61cb
Compare
|
Thank you guys again for your repeated reviews, and all of your patience with me. I believe I have resolved all of your comments, and am passing all of the test cases. Let me know of anything further. Thank you again! |
|
@Logans-olo when we talk about the update script - we're asking you to manually run llvm-project\llvm\utils\update_llc_test_checks.py on the test file to regenerate all the CHECK lines. One of your earlier comments suggested you thought it had something to with github updating the patch against trunk latest - sorry if there was any confusion. |
|
You can also use |
|
So I run build/bin/llvm-lit --update-tests llvm/test/CodeGen/X86/tbm_patterns.ll, and then move into build directory, and run ninja check-llvm-codegen. I am passing all that are supported. Is that sufficient? |
And I should be running this command and ninja after every change to a testing file correct? I think that was part of my problem as well. |
Also sorry, that's completely on me. Should know to be running (build/update) scripts after every change. I think its good now though? |
|
Is there anything I should do about the checks failing on a different test now? |
|
@Logans-olo Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
Add DAG pattern to recognize the optimized IR form of BLSIC: (xor (and x, -x), -1) Fixes llvm#209718 - matches the IR form produced after InstCombine optimizations Added tests for both 32-bit and 64-bit BLSIC patterns Assisted by: Claude Code, helped me understand pattern-matching/intrinsics, and some file structure. As well as how testing for LLVM works. (cherry picked from commit 466503d)
Add DAG pattern to recognize the optimized IR form of BLSIC: (xor (and x, -x), -1) Fixes llvm#209718 - matches the IR form produced after InstCombine optimizations Added tests for both 32-bit and 64-bit BLSIC patterns Assisted by: Claude Code, helped me understand pattern-matching/intrinsics, and some file structure. As well as how testing for LLVM works. (cherry picked from commit 466503d)
Add DAG pattern to recognize the optimized IR form of BLSIC: (xor (and x, -x), -1)
Fixes #209718 - matches the IR form produced after InstCombine optimizations
Added tests for both 32-bit and 64-bit BLSIC patterns
Assisted by: Claude Code, helped me understand pattern-matching/intrinsics, and some file structure. As well as how testing for LLVM works.