[llvm] [DAG] Early exit for flags in canCreateUndefOrPoison [nfc] (PR #89834)

Björn Pettersson via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 23 23:47:02 PDT 2024


bjope wrote:

How do we deal with (or want to deal with) things like
```
define i32 @foo(i32 %a) {
  %y = and i32 %a, 3
  %x = shl nuw nsw i32 1, %y
  ret i32 %x
}
```
The SHL DAG node will have the poison generating flags as well. But given that the shift amount is small this shift will never result in poison. Those flags are just "caching the information" that the shift won't sign wrap as detected by earlier value tracking rather than being put there to signal that the result might be poison.
Isn't it a bit weird that isGuaranteedNotToBeUndefOrPoison would return false for the SHL already without this patch?
By adding the early exit in canCreateUndefOrPoison, then it will be hard to make a more details analysis later in the function.

Maybe it is a bad thing that we both derive flags as nsw/nuw based on value tracking, while using the same flags to indicate properties of the input language (such as UB on signed overflow in C).

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


More information about the llvm-commits mailing list