[PATCH] SCEVExpander incorrectly marks increment operations as no-wrap

Andrew Trick atrick at apple.com
Wed Feb 25 23:04:20 PST 2015


Sub X Y is the canonical form though, so what SCEVExpander does makes sense, particularly if it's trying to avoid emitting redundant instructions. But it's not very smart to throw away the nuw/nsw flags unless we know they can be inferred again later.

You're right that changing this could affect codegen. Probably only for fast-isel though, and only if InstCombine isn't going to be run. So it really only matters for LoopStrengthReduce, which probably won't be run with fast-isel.

SCEVExpander could have a mode that attempts to preserve flags, and a mode where it just always generates the sub. Or you can try to generate the sub whenever it doesn't lose the flags. However, I vote for keeping it simple and just always generating the add and letting InstCombine cleanup if it actually matters. You might then want to fix InstCombine so it doesn't convert to sub and drop the flags in these cases. (actually there should be a TargetInstCombine that drops the flags just before isel, but I digress).

Incidentally, are you more often relying on nsw/nuw to be inferred within SCEV, or are you relying more on your frontend to generate them in special situations?


REPOSITORY
  rL LLVM

http://reviews.llvm.org/D7778

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the llvm-commits mailing list