[llvm] 28a3e7d - [RISCV] Override hasAndNotCompare to use more andn when have Zbb extension.
via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 22 18:51:12 PST 2021
Author: jacquesguan
Date: 2021-12-23T10:42:20+08:00
New Revision: 28a3e7dea2abb673c3dd3c08c111a6b00875bfb3
URL: https://github.com/llvm/llvm-project/commit/28a3e7dea2abb673c3dd3c08c111a6b00875bfb3
DIFF: https://github.com/llvm/llvm-project/commit/28a3e7dea2abb673c3dd3c08c111a6b00875bfb3.diff
LOG: [RISCV] Override hasAndNotCompare to use more andn when have Zbb extension.
Enable transform (X & Y) == Y ---> (~X & Y) == 0 and (X & Y) != Y ---> (~X & Y) != 0 when have Zbb extension to use more andn instruction.
Differential Revision: https://reviews.llvm.org/D115922
Added:
Modified:
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/lib/Target/RISCV/RISCVISelLowering.h
llvm/test/CodeGen/RISCV/rv32zbb-zbp.ll
llvm/test/CodeGen/RISCV/rv64zbb-zbp.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index f33965b504591..399be7abc9e68 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -1166,7 +1166,7 @@ bool RISCVTargetLowering::isCheapToSpeculateCtlz() const {
return Subtarget.hasStdExtZbb();
}
-bool RISCVTargetLowering::hasAndNot(SDValue Y) const {
+bool RISCVTargetLowering::hasAndNotCompare(SDValue Y) const {
EVT VT = Y.getValueType();
// FIXME: Support vectors once we have tests.
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.h b/llvm/lib/Target/RISCV/RISCVISelLowering.h
index 4ccfcbc50f7cc..a2d3c74ed5fd3 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.h
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.h
@@ -315,7 +315,7 @@ class RISCVTargetLowering : public TargetLowering {
bool isSExtCheaperThanZExt(EVT SrcVT, EVT DstVT) const override;
bool isCheapToSpeculateCttz() const override;
bool isCheapToSpeculateCtlz() const override;
- bool hasAndNot(SDValue Y) const override;
+ bool hasAndNotCompare(SDValue Y) const override;
bool shouldSinkOperands(Instruction *I,
SmallVectorImpl<Use *> &Ops) const override;
bool isFPImmLegal(const APFloat &Imm, EVT VT,
diff --git a/llvm/test/CodeGen/RISCV/rv32zbb-zbp.ll b/llvm/test/CodeGen/RISCV/rv32zbb-zbp.ll
index b2994fcdaf816..452de04563f0c 100644
--- a/llvm/test/CodeGen/RISCV/rv32zbb-zbp.ll
+++ b/llvm/test/CodeGen/RISCV/rv32zbb-zbp.ll
@@ -568,8 +568,7 @@ define i1 @andn_seqz_i32(i32 %a, i32 %b) nounwind {
;
; RV32ZBB-LABEL: andn_seqz_i32:
; RV32ZBB: # %bb.0:
-; RV32ZBB-NEXT: and a0, a0, a1
-; RV32ZBB-NEXT: xor a0, a0, a1
+; RV32ZBB-NEXT: andn a0, a1, a0
; RV32ZBB-NEXT: seqz a0, a0
; RV32ZBB-NEXT: ret
;
@@ -625,8 +624,7 @@ define i1 @andn_snez_i32(i32 %a, i32 %b) nounwind {
;
; RV32ZBB-LABEL: andn_snez_i32:
; RV32ZBB: # %bb.0:
-; RV32ZBB-NEXT: and a0, a0, a1
-; RV32ZBB-NEXT: xor a0, a0, a1
+; RV32ZBB-NEXT: andn a0, a1, a0
; RV32ZBB-NEXT: snez a0, a0
; RV32ZBB-NEXT: ret
;
diff --git a/llvm/test/CodeGen/RISCV/rv64zbb-zbp.ll b/llvm/test/CodeGen/RISCV/rv64zbb-zbp.ll
index be08a3ee8b1fd..dc9c37b2ba6ce 100644
--- a/llvm/test/CodeGen/RISCV/rv64zbb-zbp.ll
+++ b/llvm/test/CodeGen/RISCV/rv64zbb-zbp.ll
@@ -639,8 +639,7 @@ define i1 @andn_seqz_i32(i32 signext %a, i32 signext %b) nounwind {
;
; RV64ZBB-LABEL: andn_seqz_i32:
; RV64ZBB: # %bb.0:
-; RV64ZBB-NEXT: and a0, a0, a1
-; RV64ZBB-NEXT: xor a0, a0, a1
+; RV64ZBB-NEXT: andn a0, a1, a0
; RV64ZBB-NEXT: seqz a0, a0
; RV64ZBB-NEXT: ret
;
@@ -665,8 +664,7 @@ define i1 @andn_seqz_i64(i64 %a, i64 %b) nounwind {
;
; RV64ZBB-LABEL: andn_seqz_i64:
; RV64ZBB: # %bb.0:
-; RV64ZBB-NEXT: and a0, a0, a1
-; RV64ZBB-NEXT: xor a0, a0, a1
+; RV64ZBB-NEXT: andn a0, a1, a0
; RV64ZBB-NEXT: seqz a0, a0
; RV64ZBB-NEXT: ret
;
@@ -691,8 +689,7 @@ define i1 @andn_snez_i32(i32 signext %a, i32 signext %b) nounwind {
;
; RV64ZBB-LABEL: andn_snez_i32:
; RV64ZBB: # %bb.0:
-; RV64ZBB-NEXT: and a0, a0, a1
-; RV64ZBB-NEXT: xor a0, a0, a1
+; RV64ZBB-NEXT: andn a0, a1, a0
; RV64ZBB-NEXT: snez a0, a0
; RV64ZBB-NEXT: ret
;
@@ -717,8 +714,7 @@ define i1 @andn_snez_i64(i64 %a, i64 %b) nounwind {
;
; RV64ZBB-LABEL: andn_snez_i64:
; RV64ZBB: # %bb.0:
-; RV64ZBB-NEXT: and a0, a0, a1
-; RV64ZBB-NEXT: xor a0, a0, a1
+; RV64ZBB-NEXT: andn a0, a1, a0
; RV64ZBB-NEXT: snez a0, a0
; RV64ZBB-NEXT: ret
;
More information about the llvm-commits
mailing list