Handle ands with ~0 correctly too. This fixes PR4052.