BUG: Check earlier for higher priority in binary operators, add test

Fixes #3375
Merge pull request #3501 from inducer/master

Fix "numpy scalar * array-like == performance horror"