Skip to content

Commit

Permalink
Merge pull request #5627 from stuartarchibald/fix/5623
Browse files Browse the repository at this point in the history
Fixes #5623, SSA local def scan based on invalid equality assumption.
  • Loading branch information
sklam committed Apr 27, 2020
2 parents 205fe54 + 768cade commit 3971911
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
13 changes: 8 additions & 5 deletions numba/core/ssa.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,15 +430,18 @@ def _find_def_from_bottom(self, states, label, loc):
return self._find_def_from_top(states, label, loc=loc)

def _stmt_index(self, defstmt, block, stop=-1):
"""Find the postitional index of the statement at ``block``.
"""Find the positional index of the statement at ``block``.
Assumptions:
- no two statements can point to the same object.
"""
try:
return block.body.index(defstmt, 0, stop)
except ValueError:
return len(block.body)
# Compare using id() as IR node equality is for semantic equivalence
# opposed to direct equality (the location and scope are not considered
# as part of the equality measure, this is important here).
for i in range(len(block.body))[:stop]:
if block.body[i] is defstmt:
return i
return len(block.body)


def _warn_about_uninitialized_variable(varname, loc):
Expand Down
23 changes: 23 additions & 0 deletions numba/tests/test_ssa.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,3 +370,26 @@ def foo(m, n, data):
res2 = jit(forceobj=True, looplift=False)(foo)(10, 10, data)
np.testing.assert_array_equal(expect, res1)
np.testing.assert_array_equal(expect, res2)

def test_issue5623_equal_statements_in_same_bb(self):

def foo(pred, stack):
i = 0
c = 1

if pred is True:
stack[i] = c
i += 1
stack[i] = c
i += 1

python = np.array([0, 666])
foo(True, python)

nb = np.array([0, 666])
njit(foo)(True, nb)

expect = np.array([1, 1])

np.testing.assert_array_equal(python, expect)
np.testing.assert_array_equal(nb, expect)

0 comments on commit 3971911

Please sign in to comment.