[llvm] [Mips] Use APInt::isMask/isShiftedMask to simplify code. (PR #116582)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 17 23:30:29 PST 2024
https://github.com/topperc created https://github.com/llvm/llvm-project/pull/116582
None
>From 9a17418fe59c4069e371608f23cca8f7a61a325c Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Sun, 17 Nov 2024 23:29:03 -0800
Subject: [PATCH] [Mips] Use APInt::isMask/isShiftedMask to simplify code.
---
llvm/lib/Target/Mips/MipsSEISelDAGToDAG.cpp | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/llvm/lib/Target/Mips/MipsSEISelDAGToDAG.cpp b/llvm/lib/Target/Mips/MipsSEISelDAGToDAG.cpp
index afb027a533d5a6..c3e21e0ff7a0f0 100644
--- a/llvm/lib/Target/Mips/MipsSEISelDAGToDAG.cpp
+++ b/llvm/lib/Target/Mips/MipsSEISelDAGToDAG.cpp
@@ -614,11 +614,9 @@ bool MipsSEDAGToDAGISel::selectVSplatMaskL(SDValue N, SDValue &Imm) const {
if (selectVSplat(N.getNode(), ImmValue, EltTy.getSizeInBits()) &&
ImmValue.getBitWidth() == EltTy.getSizeInBits()) {
- // Extract the run of set bits starting with bit zero from the bitwise
- // inverse of ImmValue, and test that the inverse of this is the same
- // as the original value.
- if (ImmValue == ~(~ImmValue & ~(~ImmValue + 1))) {
-
+ // Check if we have a leading one, then check if the whole value is a
+ // shifted mask.
+ if (ImmValue.isNegative() && ImmValue.isShiftedMask()) {
Imm = CurDAG->getTargetConstant(ImmValue.popcount() - 1, SDLoc(N), EltTy);
return true;
}
@@ -647,9 +645,7 @@ bool MipsSEDAGToDAGISel::selectVSplatMaskR(SDValue N, SDValue &Imm) const {
if (selectVSplat(N.getNode(), ImmValue, EltTy.getSizeInBits()) &&
ImmValue.getBitWidth() == EltTy.getSizeInBits()) {
- // Extract the run of set bits starting with bit zero, and test that the
- // result is the same as the original value
- if (ImmValue == (ImmValue & ~(ImmValue + 1))) {
+ if (ImmValue.isMask()) {
Imm = CurDAG->getTargetConstant(ImmValue.popcount() - 1, SDLoc(N), EltTy);
return true;
}
More information about the llvm-commits
mailing list