[llvm] [TableGen] Avoid evaluating RHS of a BinOp until short-circuit is complete (PR #144021)
Jason Eckhardt via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 13 07:34:35 PDT 2025
================
@@ -67,13 +67,18 @@ def rec7 {
bits<3> flags = { true, false, true };
}
-// `!and` and `!or` should be short-circuit such that `!tail` on empty list will never
-// be evaluated.
+// `!and` and `!or` should be short-circuit such that any of the `!head` or
+// `!tail` on empty list below will never be evaluated.
// CHECK: def rec8
+// CHECK: bit v = 0;
+// CHECK: int v2 = -1;
// CHECK: list<int> newSeq = [];
// CHECK: list<int> newSeq2 = [];
class Foo <list<int> seq = []> {
+ bit v = !and(false, !head(seq));
+ int v2 = !or(-1, !head(seq));
----------------
nvjle wrote:
FWIW, `!if` is short-circuited:
```
const Init *TernOpInit::resolveReferences(Resolver &R) const {
const Init *lhs = LHS->resolveReferences(R);
if (getOpcode() == IF && lhs != LHS) {
if (const auto *Value = dyn_cast_or_null<IntInit>(
lhs->convertInitializerTo(IntRecTy::get(getRecordKeeper())))) {
// Short-circuit
if (Value->getValue())
return MHS->resolveReferences(R);
return RHS->resolveReferences(R);
```
But you are right, the documentation does not mention short-circuit explicitly, and would benefit from being updated.
https://github.com/llvm/llvm-project/pull/144021
More information about the llvm-commits
mailing list