[DAE] Adjust param/arg attributes when changing parameter to undef
authorGuozhi Wei <carrot@google.com>
Thu, 25 Mar 2021 21:50:18 +0000 (14:50 -0700)
committerGuozhi Wei <carrot@google.com>
Thu, 25 Mar 2021 21:53:22 +0000 (14:53 -0700)
commit3240910f000625957a6a01ff8758c892f72a3a0d
treedfc79ee9528c9599649ae4be0b85756f30f4c84f
parent4f5e92cc0562629ad2180b3ed2b0dad31ef7797c
[DAE] Adjust param/arg attributes when changing parameter to undef

In DeadArgumentElimination pass, if a function's argument is never used, corresponding caller's parameter can be changed to undef. If the param/arg has attribute noundef or other related attributes, LLVM LangRef(https://llvm.org/docs/LangRef.html#parameter-attributes) says its behavior is undefined. SimplifyCFG(D97244) takes advantage of this behavior and does bad transformation on valid code.

To avoid this undefined behavior when change caller's parameter to undef, this patch removes noundef attribute and other attributes imply noundef on param/arg.

Differential Revision: https://reviews.llvm.org/D98899
llvm/include/llvm/IR/Attributes.h
llvm/include/llvm/IR/Function.h
llvm/include/llvm/IR/InstrTypes.h
llvm/lib/IR/Attributes.cpp
llvm/lib/IR/Function.cpp
llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp
llvm/test/Transforms/DeadArgElim/NoundefAttrs.ll [new file with mode: 0644]
llvm/test/Transforms/InstCombine/unused-nonnull.ll