[llvm] [AMDGPU] Compute GISel KnownBits for S_BFE instructions (PR #141588)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 25 02:07:44 PDT 2025
================
@@ -16783,12 +16783,66 @@ static void knownBitsForWorkitemID(const GCNSubtarget &ST,
Known.Zero.setHighBits(llvm::countl_zero(MaxValue));
}
+static void knownBitsForSBFE(const MachineInstr &MI, GISelValueTracking &VT,
+ KnownBits &Known, const APInt &DemandedElts,
+ unsigned BFEWidth, bool SExt, unsigned Depth) {
+ const MachineRegisterInfo &MRI = VT.getMachineFunction().getRegInfo();
+ const MachineOperand &Src1 = MI.getOperand(2);
+
+ unsigned Src1Cst = 0;
+ if (Src1.isImm()) {
+ Src1Cst = Src1.getImm();
+ } else if (Src1.isReg()) {
+ auto Cst = getIConstantVRegValWithLookThrough(Src1.getReg(), MRI);
+ if (!Cst)
+ return;
+ Src1Cst = Cst->Value.getZExtValue();
+ } else {
+ return;
+ }
+
+ // Offset is at bits [4:0] for 32 bit, [5:0] for 64 bit.
+ // Width is always [22:16].
+ const unsigned Offset =
+ Src1Cst & maskTrailingOnes<unsigned>((BFEWidth == 32) ? 5 : 6);
+ const unsigned Width = (Src1Cst >> 16) & maskTrailingOnes<unsigned>(6);
+
+ if (Width >= BFEWidth) // Ill-formed.
+ return;
+
+ VT.computeKnownBitsImpl(MI.getOperand(1).getReg(), Known, DemandedElts,
+ Depth + 1);
+
+ Known.Zero = Known.Zero.lshr(Offset);
+ Known.One = Known.One.lshr(Offset);
+
+ Known = Known.trunc(Width);
----------------
jayfoad wrote:
```suggestion
Known = Known.extractBits(Width, Offset);
```
https://github.com/llvm/llvm-project/pull/141588
More information about the llvm-commits
mailing list