[llvm] [SCCP] Refine trunc with nsw/nuw flags (PR #87926)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 15 04:29:43 PDT 2024


dtcxzyw wrote:

> > LGTM. BTW, as adding poison-generating flags blocks `logical and/or -> bitwise and/or`, should we take context information into account in `canCreateUndefOrPoison`?
> 
> Can you clarify what you mean by "take context information into account" here?

Example: https://godbolt.org/z/vYTfazrd3
```
define i1 @test(i8 noundef %x, i1 %cond) {
  %cmp = icmp ult i8 %x, 2 
  br i1 %cmp, label %if.then, label %if.else

if.then:
  %trunc = trunc nuw i8 %x to i1
  %sel = select i1 %trunc, i1 %cond, i1 false
  ret i1 %sel

if.else:
  ret i1 false
}
```
In this case, we can turn the logical and into a bitwise and by recomputing knownbits of `%x`.

> 
> Generally, I think it's more important to make transforms work with the logical form than improve logical -> bitwise conversion. I wouldn't consider the conversion itself not happening a significant regression, only if this disables downstream optimizations.

See also https://github.com/llvm/llvm-project/pull/84924.


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


More information about the llvm-commits mailing list