[PATCH] D142115: [ValueTracking] Take poison-generating metadata into account (PR59888)

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 19 07:16:23 PST 2023


nikic created this revision.
nikic added reviewers: spatel, nlopes.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
nikic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

In canCreateUndefOrPoison(), take not only poison-generating flags, but also poison-generating metadata into account. The helpers are written generally, but I believe the only case that can actually matter is `!range` on calls -- `!nonnull` and `!align` are only valid on loads, can those can create undef/poison anyway.

Unfortunately, this negatively impacts logical to bitwise and/or conversion: For ctpop/ctlz/cttz we always attach `!range` metadata, which will now block the transform, because it might introduce poison. Of course, the metadata we attach cannot actually produce new poison, but this is not generally the case (it could be an incorrect range).

I'm a bit unsure on what to do about this. A possibility would be to update the impliesPoison() helper to support ConsiderFlagsAndMetadata=false mode, and collect instructions that it has checked, and then drop poison generating flags/metadata on all those instructions.

Fixes https://github.com/llvm/llvm-project/issues/59888.


https://reviews.llvm.org/D142115

Files:
  llvm/include/llvm/Analysis/ValueTracking.h
  llvm/include/llvm/IR/Instruction.h
  llvm/include/llvm/IR/Operator.h
  llvm/lib/Analysis/ValueTracking.cpp
  llvm/lib/IR/Instruction.cpp
  llvm/lib/IR/Operator.cpp
  llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
  llvm/test/Transforms/InstCombine/freeze.ll
  llvm/test/Transforms/InstCombine/ispow2.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142115.490505.patch
Type: text/x-patch
Size: 13486 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230119/3732351e/attachment.bin>


More information about the llvm-commits mailing list