[PATCH] D94180: [SimplifyCFG] Optimize CFG when null is passed to a function with nonnull argument.

Juneyoung Lee via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 6 18:25:14 PST 2021


aqjune added a comment.

Yeah, I believe passing null to nonnull should not immediately raise UB; it will block useful analyses. The patch is D90529 <https://reviews.llvm.org/D90529>, and I need to push it... Maybe it is time to reduce the number of patches that are still open by me.

For the example, I think this InstCombine transformation will work. noundef isn't necessary.

  %s = select i1 %cond, i8* null, i8* %a
  call void @foo(i8* nonnull %s)
  ->
  call void @foo(i8* nonnull %a)

This is correct because
(1) If %cond was true, foo's argument is `nonnull null` which is equivalent to passing poison. Therefore it can be folded into arbitrary value such as %a.
(2) If %cond was false, it is already %a, so that's fine.

For the SimplifyCFG change, noundef is necessary. :) Maybe we can have both SimplifyCFG and InstCombine?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94180



More information about the llvm-commits mailing list