[llvm] [RISCV] Refactor X60 scheduling model helper classes. NFC. (PR #151572)

Mikhail R. Gadelha via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 2 11:27:10 PDT 2025


mikhailramalho wrote:

Thanks, I see the issue now, the function is:
```
class ConstValueUntilLMULThenDoubleBase<string startLMUL, int BaseValue, int Value, string currentLMUL> {
  assert !le(BaseValue, Value), "BaseValue must be le to Value";
  defvar startPos = GetLMULValue<[0, 1, 2, 3, 4, 5, 6], startLMUL>.c;
  defvar currentPos = GetLMULValue<[0, 1, 2, 3, 4, 5, 6], currentLMUL>.c;

  // Calculate the difference in positions
  defvar posDiff = !sub(currentPos, startPos);

  // Calculate Value * (2^posDiff) using shift left
  int c = !cond(
    !lt(posDiff, 0) : BaseValue,
    !eq(posDiff, 0) : Value,
    true: !mul(Value, !shl(1, posDiff))
  );
}
```
For example, if I call `ConstValueUntilLMULThenDoubleBase<"M2", 4, 4, mx>.c;`, I get:
```
startPos = 4
currentPos = 0
posDiff = -4
!mul(Value, !shl(1, posDiff)) = 4611686018427387904
```
However, the result is never used because we take the `!lt(posDiff, 0) : BaseValue` branch in cond, but the `true: !mul(Value, !shl(1, posDiff))` branch is still being evaluated...

Is there a way in tablegen to do the evaluation lazily? Otherwise, I can go back to the previous version that doesn't use shifts:
```
  int c = !cond(
    true : BaseValue,
    !eq(posDiff, 0) : Value,
    !eq(posDiff, 1) : !mul(Value, 2),
    !eq(posDiff, 2) : !mul(Value, 4),
    !eq(posDiff, 3) : !mul(Value, 8),
    !eq(posDiff, 4) : !mul(Value, 16),
    !eq(posDiff, 5) : !mul(Value, 32),
    !eq(posDiff, 6) : !mul(Value, 64)
  );
```

https://github.com/llvm/llvm-project/pull/151572


More information about the llvm-commits mailing list