Skip to content

Commit b20cf29

Browse files
committed
Only short circuit against the left-most operand
And cleanup the test
1 parent 8cce6ce commit b20cf29

File tree

3 files changed

+6
-16
lines changed

3 files changed

+6
-16
lines changed

llvm/docs/TableGen/ProgRef.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,7 +1646,7 @@ and non-0 as true.
16461646
``!and(``\ *a*\ ``,`` *b*\ ``, ...)``
16471647
This operator does a bitwise AND on *a*, *b*, etc., and produces the
16481648
result. A logical AND can be performed if all the arguments are either
1649-
0 or 1. This operator is short-circuit to 0 when one of the operands
1649+
0 or 1. This operator is short-circuit to 0 when the left-most operand
16501650
is 0.
16511651

16521652
``!cast<``\ *type*\ ``>(``\ *a*\ ``)``
@@ -1873,8 +1873,8 @@ and non-0 as true.
18731873
``!or(``\ *a*\ ``,`` *b*\ ``, ...)``
18741874
This operator does a bitwise OR on *a*, *b*, etc., and produces the
18751875
result. A logical OR can be performed if all the arguments are either
1876-
0 or 1. This operator is short-circuit to -1 (all ones) if one of the
1877-
operands is -1.
1876+
0 or 1. This operator is short-circuit to -1 (all ones) the left-most
1877+
operand is -1.
18781878

18791879
``!range([``\ *start*\ ``,]`` *end*\ ``[,``\ *step*\ ``])``
18801880
This operator produces half-open range sequence ``[start : end : step)`` as

llvm/lib/TableGen/Record.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,12 +1558,6 @@ const Init *BinOpInit::resolveReferences(Resolver &R) const {
15581558
(Opc == OR && LHSi->getValue() == -1))
15591559
return LHSi;
15601560
}
1561-
if (const auto *RHSi = dyn_cast_or_null<IntInit>(
1562-
rhs->convertInitializerTo(IntRecTy::get(getRecordKeeper())))) {
1563-
if ((Opc == AND && !RHSi->getValue()) ||
1564-
(Opc == OR && RHSi->getValue() == -1))
1565-
return RHSi;
1566-
}
15671561
}
15681562

15691563
if (LHS != lhs || RHS != rhs)

llvm/test/TableGen/true-false.td

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,11 @@ def rec7 {
7272
// CHECK: def rec8
7373
// CHECK: list<int> newSeq = [];
7474
// CHECK: list<int> newSeq2 = [];
75-
// CHECK: list<int> newSeq3 = [];
76-
// CHECK: list<int> newSeq4 = [];
7775

7876
class Foo <list<int> seq = []> {
79-
bit containsStr = !ne(!find(NAME, "BAR"), -1);
80-
list<int> newSeq = !if(!and(!not(!empty(seq)), containsStr), !tail(seq), seq);
81-
list<int> newSeq2 = !if(!and(containsStr, !not(!empty(seq))), !tail(seq), seq);
82-
list<int> newSeq3 = !if(!or(containsStr, -1), seq, !tail(seq));
83-
list<int> newSeq4 = !if(!or(-1, containsStr), seq, !tail(seq));
77+
bit unresolved = !ne(!find(NAME, "BAR"), -1);
78+
list<int> newSeq = !if(!and(false, unresolved), !tail(seq), seq);
79+
list<int> newSeq2 = !if(!or(-1, unresolved), seq, !tail(seq));
8480
}
8581

8682
def rec8 : Foo<>;

0 commit comments

Comments
 (0)