[llvm] [InstCombine] Fold `(icmp pred (trunc nuw/nsw X), C)` -> `(icmp pred X, (zext/sext C))` (PR #87935)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 9 19:24:06 PDT 2024


nikic wrote:

> > Generally fine, but before we start using trunc nuw/nsw in optimizations we need to perform some due diligence. Based on past experience, we very likely have folds that incorrectly preserve the nuw/nsw flag now.
> > Approach is basically 1. replace "trunc" with "trunc nuw" in existing tests, 2. check whether there are failures with alive2, 3. repeat with trunc nsw. Let me know if you would be interested in doing that...
> 
> Ill look into that. I would think the only way this really becomes an issue is if we have `replaceOperand` on a `trunc`. Any other use case we would erroneously preserve flags?

It tends to be either in-place modification, or returning of existing values. Here's a couple examples of issues I ran into with disjoint or: https://github.com/llvm/llvm-project/commit/d8bc5465330474b80c02ca37e76a9a51245f1d79 https://github.com/llvm/llvm-project/commit/07c18a05e2cb80e87b0c681c147a253565064f3e https://github.com/llvm/llvm-project/commit/cd31cf5989aaf6a187aaf3af4f94207c55a70d0f We had similar with zext nneg. Most likely there will be some for trunc nuw/nsw as well.

https://github.com/llvm/llvm-project/pull/87935


More information about the llvm-commits mailing list