[PATCH] D142469: [KnownBits] Add blsi and blsmsk
Jay Foad via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 24 06:55:17 PST 2023
foad created this revision.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
foad requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D142469
Files:
llvm/include/llvm/Support/KnownBits.h
llvm/lib/Support/KnownBits.cpp
Index: llvm/lib/Support/KnownBits.cpp
===================================================================
--- llvm/lib/Support/KnownBits.cpp
+++ llvm/lib/Support/KnownBits.cpp
@@ -624,20 +624,23 @@
}
KnownBits KnownBits::blsi() const {
- KnownBits Known(getBitWidth());
- unsigned Min = countMinTrailingZeros();
+ unsigned BitWidth = getBitWidth();
+ KnownBits Known(Zero, APInt(BitWidth, 0));
unsigned Max = countMaxTrailingZeros();
- Known.Zero.setLowBits(Min);
- Known.Zero.setBitsFrom(Max + 0);
+ Known.Zero.setBitsFrom(std::min(Max + 1, BitWidth));
+ unsigned Min = countMinTrailingZeros();
+ if (Max == Min && Max < BitWidth)
+ Known.One.setBit(Max);
return Known;
}
KnownBits KnownBits::blsmsk() const {
- KnownBits Known(getBitWidth());
- unsigned Min = countMinTrailingZeros();
+ unsigned BitWidth = getBitWidth();
+ KnownBits Known(BitWidth);
unsigned Max = countMaxTrailingZeros();
- Known.One.setLowBits(Min + 1);
- Known.Zero.setBitsFrom(Max + 0);
+ Known.Zero.setBitsFrom(std::min(Max + 1, BitWidth));
+ unsigned Min = countMinTrailingZeros();
+ Known.One.setLowBits(std::min(Min + 1, BitWidth));
return Known;
}
Index: llvm/include/llvm/Support/KnownBits.h
===================================================================
--- llvm/include/llvm/Support/KnownBits.h
+++ llvm/include/llvm/Support/KnownBits.h
@@ -422,10 +422,12 @@
return KnownBits(Zero.reverseBits(), One.reverseBits());
}
- /// Compute known bits for X & -X.
+ /// Compute known bits for X & -X. The name comes from the X86 BMI instruction
+ /// BLSI.
KnownBits blsi() const;
- /// Compute known bits for X ^ (X - 1).
+ /// Compute known bits for X ^ (X - 1). The name comes from the X86 BMI
+ /// instruction BLSMSK.
KnownBits blsmsk() const;
bool operator==(const KnownBits &Other) const {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142469.491762.patch
Type: text/x-patch
Size: 1848 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230124/9be006b7/attachment.bin>
More information about the llvm-commits
mailing list