[llvm] 8a98091 - [RISCV] Use disjoint flag in or_is_add.
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 30 22:12:45 PST 2024
Author: Craig Topper
Date: 2024-01-30T22:12:28-08:00
New Revision: 8a98091162841fabc3816f3f29380c930ccbcab5
URL: https://github.com/llvm/llvm-project/commit/8a98091162841fabc3816f3f29380c930ccbcab5
DIFF: https://github.com/llvm/llvm-project/commit/8a98091162841fabc3816f3f29380c930ccbcab5.diff
LOG: [RISCV] Use disjoint flag in or_is_add.
Added:
Modified:
llvm/lib/Target/RISCV/RISCVInstrInfo.td
llvm/test/CodeGen/RISCV/or-is-add.ll
llvm/test/CodeGen/RISCV/rv64-legal-i32/rv64zba.ll
llvm/test/CodeGen/RISCV/rv64zba.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.td b/llvm/lib/Target/RISCV/RISCVInstrInfo.td
index 114329c2c7c5f..67f73b228af72 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfo.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfo.td
@@ -1248,6 +1248,8 @@ def : PatGprUimmLog2XLen<sra, SRAI>;
// Select 'or' as ADDI if the immediate bits are known to be 0 in $rs1. This
// can improve compressibility.
def or_is_add : PatFrag<(ops node:$lhs, node:$rhs), (or node:$lhs, node:$rhs),[{
+ if (N->getFlags().hasDisjoint())
+ return true;
KnownBits Known0 = CurDAG->computeKnownBits(N->getOperand(0), 0);
KnownBits Known1 = CurDAG->computeKnownBits(N->getOperand(1), 0);
return KnownBits::haveNoCommonBitsSet(Known0, Known1);
diff --git a/llvm/test/CodeGen/RISCV/or-is-add.ll b/llvm/test/CodeGen/RISCV/or-is-add.ll
index 853dd20b97ad2..36a201d277675 100644
--- a/llvm/test/CodeGen/RISCV/or-is-add.ll
+++ b/llvm/test/CodeGen/RISCV/or-is-add.ll
@@ -107,3 +107,17 @@ define i64 @test6(i64 %x) {
%b = xor i64 %a, 1024
ret i64 %b
}
+
+define signext i32 @test7(i32 signext %x) {
+; RV32-LABEL: test7:
+; RV32: # %bb.0:
+; RV32-NEXT: addi a0, a0, 1
+; RV32-NEXT: ret
+;
+; RV64-LABEL: test7:
+; RV64: # %bb.0:
+; RV64-NEXT: ori a0, a0, 1
+; RV64-NEXT: ret
+ %a = or disjoint i32 %x, 1
+ ret i32 %a
+}
diff --git a/llvm/test/CodeGen/RISCV/rv64-legal-i32/rv64zba.ll b/llvm/test/CodeGen/RISCV/rv64-legal-i32/rv64zba.ll
index 06bebb29a04b9..90cfb1fdcb779 100644
--- a/llvm/test/CodeGen/RISCV/rv64-legal-i32/rv64zba.ll
+++ b/llvm/test/CodeGen/RISCV/rv64-legal-i32/rv64zba.ll
@@ -1891,3 +1891,37 @@ define i64 @pack_i64_3(i32 signext %a, i32 signext %b) nounwind {
%or = or i64 %shl1, %zexta
ret i64 %or
}
+
+define i64 @pack_i64_disjoint(i64 %a, i64 %b) nounwind {
+; RV64I-LABEL: pack_i64_disjoint:
+; RV64I: # %bb.0:
+; RV64I-NEXT: slli a0, a0, 32
+; RV64I-NEXT: srli a0, a0, 32
+; RV64I-NEXT: or a0, a1, a0
+; RV64I-NEXT: ret
+;
+; RV64ZBA-LABEL: pack_i64_disjoint:
+; RV64ZBA: # %bb.0:
+; RV64ZBA-NEXT: add.uw a0, a0, a1
+; RV64ZBA-NEXT: ret
+ %shl = and i64 %a, 4294967295
+ %or = or disjoint i64 %b, %shl
+ ret i64 %or
+}
+
+define i64 @pack_i64_disjoint_2(i32 signext %a, i64 %b) nounwind {
+; RV64I-LABEL: pack_i64_disjoint_2:
+; RV64I: # %bb.0:
+; RV64I-NEXT: slli a0, a0, 32
+; RV64I-NEXT: srli a0, a0, 32
+; RV64I-NEXT: or a0, a1, a0
+; RV64I-NEXT: ret
+;
+; RV64ZBA-LABEL: pack_i64_disjoint_2:
+; RV64ZBA: # %bb.0:
+; RV64ZBA-NEXT: add.uw a0, a0, a1
+; RV64ZBA-NEXT: ret
+ %zexta = zext i32 %a to i64
+ %or = or disjoint i64 %b, %zexta
+ ret i64 %or
+}
diff --git a/llvm/test/CodeGen/RISCV/rv64zba.ll b/llvm/test/CodeGen/RISCV/rv64zba.ll
index 9b472523875e7..f810f51f6bc07 100644
--- a/llvm/test/CodeGen/RISCV/rv64zba.ll
+++ b/llvm/test/CodeGen/RISCV/rv64zba.ll
@@ -1823,3 +1823,37 @@ define i64 @pack_i64_2(i32 signext %a, i32 signext %b) nounwind {
%or = or i64 %shl1, %zexta
ret i64 %or
}
+
+define i64 @pack_i64_disjoint(i64 %a, i64 %b) nounwind {
+; RV64I-LABEL: pack_i64_disjoint:
+; RV64I: # %bb.0:
+; RV64I-NEXT: slli a0, a0, 32
+; RV64I-NEXT: srli a0, a0, 32
+; RV64I-NEXT: or a0, a1, a0
+; RV64I-NEXT: ret
+;
+; RV64ZBA-LABEL: pack_i64_disjoint:
+; RV64ZBA: # %bb.0:
+; RV64ZBA-NEXT: add.uw a0, a0, a1
+; RV64ZBA-NEXT: ret
+ %shl = and i64 %a, 4294967295
+ %or = or disjoint i64 %b, %shl
+ ret i64 %or
+}
+
+define i64 @pack_i64_disjoint_2(i32 signext %a, i64 %b) nounwind {
+; RV64I-LABEL: pack_i64_disjoint_2:
+; RV64I: # %bb.0:
+; RV64I-NEXT: slli a0, a0, 32
+; RV64I-NEXT: srli a0, a0, 32
+; RV64I-NEXT: or a0, a1, a0
+; RV64I-NEXT: ret
+;
+; RV64ZBA-LABEL: pack_i64_disjoint_2:
+; RV64ZBA: # %bb.0:
+; RV64ZBA-NEXT: add.uw a0, a0, a1
+; RV64ZBA-NEXT: ret
+ %zexta = zext i32 %a to i64
+ %or = or disjoint i64 %b, %zexta
+ ret i64 %or
+}
More information about the llvm-commits
mailing list