[PATCH] D98391: [InstSimplify] Set UseInstrInfo to false when calling SimplifyWithOpReplaced

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 12 02:27:23 PST 2021


nikic added a comment.

I'm not sure this is moving in the right direction. It should be noted that the primary refinement problem in SimplifyWithOpReplaced, which we have encountered in various forms in the past, is along the lines of folding `add nuw UINT_MAX, 1` to `0` and thus refining poision to zero. The key here is that this would be valid without the `nuw` flag. This is the converse problem of what `UseInstrInfo` is solving. In fact, if `add nuw UINT_MAX, 1` is folded to `poison`, then that result is okay to use, as no refinement occurs. This can also be seen in the changes to stripPointerCasts you are making -- effectively you are preventing optimization across inbounds GEP, even though the point of `UseInstrInfo` is to optimize without making use of the inbounds information.

I don't think there's any easy principled solution here, so what I'd do instead is to just extend the existing canCreatePoison() hack, which has served us well enough in practice, to also go one level up for compare instructions. (The more definitive way to prevent issues is to check that it isGuaranteedNotUndefOrPoison, but I expect that this would break many transforms.)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98391/new/

https://reviews.llvm.org/D98391



More information about the llvm-commits mailing list