Fix optimization's side effect and micro-optimize some cases of label checking