[ValueTracking] Treat branch on undef as UB as well
authorNikita Popov <npopov@redhat.com>
Mon, 2 Jan 2023 10:16:09 +0000 (11:16 +0100)
committerNikita Popov <npopov@redhat.com>
Mon, 2 Jan 2023 11:34:23 +0000 (12:34 +0100)
commite44b11d9b6baa0bfc3d864d455a4b5717499f05b
tree95939c0799331196002f1db5737c277c40359260
parent09778940d1aea0cd3ff99df47cd2dc2fe5b09bb9
[ValueTracking] Treat branch on undef as UB as well

We were already treating branch on poison as UB, but branch on
undef is also UB. Move the checks into the correct function.

From LangRef for br:

> If ‘cond’ is poison or undef, this instruction has undefined behavior.

From LangRef for switch:

> If ‘value’ is poison or undef, this instruction has undefined behavior.

There is a minor regression in dont-distribute-phi.ll, apparently
we handle that pattern in logical but not bitwise form.
28 files changed:
llvm/lib/Analysis/ValueTracking.cpp
llvm/test/Transforms/Attributor/ArgumentPromotion/control-flow.ll
llvm/test/Transforms/Attributor/IPConstantProp/return-argument.ll
llvm/test/Transforms/Attributor/IPConstantProp/return-constant.ll
llvm/test/Transforms/Attributor/IPConstantProp/return-constants.ll
llvm/test/Transforms/Attributor/IPConstantProp/solve-after-each-resolving-undefs-for-function.ll
llvm/test/Transforms/Attributor/align.ll
llvm/test/Transforms/Attributor/dereferenceable-1.ll
llvm/test/Transforms/Attributor/dereferenceable-2-inseltpoison.ll
llvm/test/Transforms/Attributor/dereferenceable-2.ll
llvm/test/Transforms/Attributor/memory_locations.ll
llvm/test/Transforms/Attributor/multiple-offsets-pointer-info.ll
llvm/test/Transforms/Attributor/nocapture-1.ll
llvm/test/Transforms/Attributor/nonnull.ll
llvm/test/Transforms/Attributor/norecurse.ll
llvm/test/Transforms/Attributor/nounwind.ll
llvm/test/Transforms/Attributor/potential.ll
llvm/test/Transforms/Attributor/range.ll
llvm/test/Transforms/Attributor/reduced/crash_ptr2int_cgscc.ll
llvm/test/Transforms/Attributor/returned.ll
llvm/test/Transforms/Attributor/undefined_behavior.ll
llvm/test/Transforms/Attributor/value-simplify-assume.ll
llvm/test/Transforms/Attributor/value-simplify-instances.ll
llvm/test/Transforms/Attributor/value-simplify-pointer-info.ll
llvm/test/Transforms/Attributor/value-simplify-reachability.ll
llvm/test/Transforms/Attributor/value-simplify.ll
llvm/test/Transforms/Attributor/willreturn.ll
llvm/test/Transforms/InstCombine/dont-distribute-phi.ll