[llvm] [SPIRV] Fix trunc nonstandard int types (PR #191393)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 13 08:15:23 PDT 2026
================
@@ -397,25 +397,40 @@ static unsigned widenBitWidthToNextPow2(unsigned BitWidth) {
return std::min(std::max(1u << Log2_32_Ceil(BitWidth), 8u), 128u);
}
-static void widenScalarType(Register Reg, MachineRegisterInfo &MRI) {
+static unsigned widenScalarType(Register Reg, MachineRegisterInfo &MRI) {
+ // Returns original size or 0 if no change.
LLT RegType = MRI.getType(Reg);
if (!RegType.isScalar())
- return;
+ return 0;
unsigned CurrentWidth = RegType.getScalarSizeInBits();
unsigned NewWidth = widenBitWidthToNextPow2(CurrentWidth);
- if (NewWidth != CurrentWidth)
+ if (NewWidth != CurrentWidth) {
MRI.setType(Reg, LLT::scalar(NewWidth));
+ return CurrentWidth;
+ }
+ return 0;
}
-static void widenCImmType(MachineOperand &MOP) {
+static unsigned widenCImmType(MachineOperand &MOP) {
+ // Returns original size or 0 if no change.
const ConstantInt *CImmVal = MOP.getCImm();
unsigned CurrentWidth = CImmVal->getBitWidth();
unsigned NewWidth = widenBitWidthToNextPow2(CurrentWidth);
- if (NewWidth != CurrentWidth) {
- // Replace the immediate value with the widened version
- MOP.setCImm(ConstantInt::get(CImmVal->getType()->getContext(),
- CImmVal->getValue().zextOrTrunc(NewWidth)));
- }
+ if (NewWidth == CurrentWidth)
+ return 0;
+
+ // Replace the immediate value with the widened version.
+ MOP.setCImm(ConstantInt::get(CImmVal->getType()->getContext(),
+ CImmVal->getValue().zextOrTrunc(NewWidth)));
+ return CurrentWidth;
+}
+
+static unsigned widenOperand(MachineOperand &MOP, MachineRegisterInfo &MRI) {
+ // Returns original size or 0 if no change.
+ if (MOP.isReg())
+ return widenScalarType(MOP.getReg(), MRI);
+ else if (MOP.isCImm())
+ return widenCImmType(MOP);
}
----------------
idubinov wrote:
not related anymore
https://github.com/llvm/llvm-project/pull/191393
More information about the llvm-commits
mailing list