-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
[RISCV][ISel] Select binvi
for pattern icmp eq/ne X, pow2
#110957
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-backend-risc-v Author: Yingwei Zheng (dtcxzyw) ChangesThis patch selects Full diff: https://github.com/llvm/llvm-project/pull/110957.diff 3 Files Affected:
diff --git a/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp b/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
index 3e3f3c2eca1468..dc3f8254cb4e00 100644
--- a/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
@@ -2938,6 +2938,14 @@ bool RISCVDAGToDAGISel::selectSETCC(SDValue N, ISD::CondCode ExpectedCCVal,
0);
return true;
}
+ if (isPowerOf2_64(CVal) && Subtarget->hasStdExtZbs()) {
+ Val = SDValue(
+ CurDAG->getMachineNode(
+ RISCV::BINVI, DL, N->getValueType(0), LHS,
+ CurDAG->getTargetConstant(Log2_64(CVal), DL, N->getValueType(0))),
+ 0);
+ return true;
+ }
}
// If nothing else we can XOR the LHS and RHS to produce zero if they are
diff --git a/llvm/test/CodeGen/RISCV/rv32zbs.ll b/llvm/test/CodeGen/RISCV/rv32zbs.ll
index 30aba61ba47469..c0b9e0b3c7748e 100644
--- a/llvm/test/CodeGen/RISCV/rv32zbs.ll
+++ b/llvm/test/CodeGen/RISCV/rv32zbs.ll
@@ -837,3 +837,49 @@ define i64 @bset_trailing_ones_i64_no_mask(i64 %a) nounwind {
%not = xor i64 %shift, -1
ret i64 %not
}
+
+define i1 @icmp_eq_pow2(i32 %x) nounwind {
+; RV32I-LABEL: icmp_eq_pow2:
+; RV32I: # %bb.0:
+; RV32I-NEXT: lui a1, 8
+; RV32I-NEXT: xor a0, a0, a1
+; RV32I-NEXT: seqz a0, a0
+; RV32I-NEXT: ret
+;
+; RV32ZBS-LABEL: icmp_eq_pow2:
+; RV32ZBS: # %bb.0:
+; RV32ZBS-NEXT: binvi a0, a0, 15
+; RV32ZBS-NEXT: seqz a0, a0
+; RV32ZBS-NEXT: ret
+ %cmp = icmp eq i32 %x, 32768
+ ret i1 %cmp
+}
+
+define i1 @icmp_ne_pow2(i32 %x) nounwind {
+; RV32I-LABEL: icmp_ne_pow2:
+; RV32I: # %bb.0:
+; RV32I-NEXT: lui a1, 8
+; RV32I-NEXT: xor a0, a0, a1
+; RV32I-NEXT: seqz a0, a0
+; RV32I-NEXT: ret
+;
+; RV32ZBS-LABEL: icmp_ne_pow2:
+; RV32ZBS: # %bb.0:
+; RV32ZBS-NEXT: binvi a0, a0, 15
+; RV32ZBS-NEXT: seqz a0, a0
+; RV32ZBS-NEXT: ret
+ %cmp = icmp eq i32 %x, 32768
+ ret i1 %cmp
+}
+
+define i1 @icmp_eq_nonpow2(i32 %x) nounwind {
+; CHECK-LABEL: icmp_eq_nonpow2:
+; CHECK: # %bb.0:
+; CHECK-NEXT: lui a1, 8
+; CHECK-NEXT: addi a1, a1, -1
+; CHECK-NEXT: xor a0, a0, a1
+; CHECK-NEXT: seqz a0, a0
+; CHECK-NEXT: ret
+ %cmp = icmp eq i32 %x, 32767
+ ret i1 %cmp
+}
diff --git a/llvm/test/CodeGen/RISCV/rv64zbs.ll b/llvm/test/CodeGen/RISCV/rv64zbs.ll
index d370b1877470c4..577005a051b204 100644
--- a/llvm/test/CodeGen/RISCV/rv64zbs.ll
+++ b/llvm/test/CodeGen/RISCV/rv64zbs.ll
@@ -1146,3 +1146,67 @@ define signext i64 @bset_trailing_ones_i64_no_mask(i64 signext %a) nounwind {
%not = xor i64 %shift, -1
ret i64 %not
}
+
+define i1 @icmp_eq_pow2(i32 signext %x) nounwind {
+; RV64I-LABEL: icmp_eq_pow2:
+; RV64I: # %bb.0:
+; RV64I-NEXT: lui a1, 8
+; RV64I-NEXT: xor a0, a0, a1
+; RV64I-NEXT: seqz a0, a0
+; RV64I-NEXT: ret
+;
+; RV64ZBS-LABEL: icmp_eq_pow2:
+; RV64ZBS: # %bb.0:
+; RV64ZBS-NEXT: binvi a0, a0, 15
+; RV64ZBS-NEXT: seqz a0, a0
+; RV64ZBS-NEXT: ret
+ %cmp = icmp eq i32 %x, 32768
+ ret i1 %cmp
+}
+
+define i1 @icmp_eq_pow2_64(i64 %x) nounwind {
+; RV64I-LABEL: icmp_eq_pow2_64:
+; RV64I: # %bb.0:
+; RV64I-NEXT: li a1, 1
+; RV64I-NEXT: slli a1, a1, 40
+; RV64I-NEXT: xor a0, a0, a1
+; RV64I-NEXT: seqz a0, a0
+; RV64I-NEXT: ret
+;
+; RV64ZBS-LABEL: icmp_eq_pow2_64:
+; RV64ZBS: # %bb.0:
+; RV64ZBS-NEXT: binvi a0, a0, 40
+; RV64ZBS-NEXT: seqz a0, a0
+; RV64ZBS-NEXT: ret
+ %cmp = icmp eq i64 %x, 1099511627776
+ ret i1 %cmp
+}
+
+define i1 @icmp_ne_pow2(i32 signext %x) nounwind {
+; RV64I-LABEL: icmp_ne_pow2:
+; RV64I: # %bb.0:
+; RV64I-NEXT: lui a1, 8
+; RV64I-NEXT: xor a0, a0, a1
+; RV64I-NEXT: seqz a0, a0
+; RV64I-NEXT: ret
+;
+; RV64ZBS-LABEL: icmp_ne_pow2:
+; RV64ZBS: # %bb.0:
+; RV64ZBS-NEXT: binvi a0, a0, 15
+; RV64ZBS-NEXT: seqz a0, a0
+; RV64ZBS-NEXT: ret
+ %cmp = icmp eq i32 %x, 32768
+ ret i1 %cmp
+}
+
+define i1 @icmp_eq_nonpow2(i32 signext %x) nounwind {
+; CHECK-LABEL: icmp_eq_nonpow2:
+; CHECK: # %bb.0:
+; CHECK-NEXT: lui a1, 8
+; CHECK-NEXT: addiw a1, a1, -1
+; CHECK-NEXT: xor a0, a0, a1
+; CHECK-NEXT: seqz a0, a0
+; CHECK-NEXT: ret
+ %cmp = icmp eq i32 %x, 32767
+ ret i1 %cmp
+}
|
dtcxzyw
added a commit
to dtcxzyw/llvm-codegen-benchmark
that referenced
this pull request
Oct 3, 2024
topperc
approved these changes
Oct 3, 2024
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.
LGTM
xgupta
pushed a commit
to xgupta/llvm-project
that referenced
this pull request
Oct 4, 2024
…10957) This patch selects `binvi` for pattern `icmp eq/ne X, pow2` when zbs is available.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This patch selects
binvi
for patternicmp eq/ne X, pow2
when zbs is available.