[DAG] Strip poison generating flags in freeze(op()) -> op(freeze()) fold
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Fri, 26 Aug 2022 10:47:44 +0000 (11:47 +0100)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Fri, 26 Aug 2022 10:47:51 +0000 (11:47 +0100)
commit88c7b16bede8a0b070fd74f05e0ae88833629e5b
treebebc9a5f5edc63117da6abc692eef01f04adf42c
parentf964417c32d05a88c80db315e97ada639d97eda1
[DAG] Strip poison generating flags in freeze(op()) -> op(freeze()) fold

This patch follows the InstCombine approach of stripping poison generating flags (nsw/nuw from add/sub etc.) to allow us to push a freeze() through the op. Unlike InstCombine it doesn't retain any flags, but we have plenty of DAG folds that do the same thing already. We assert that the newly generated op isGuaranteedNotToBeUndefOrPoison.

Similar to the ValueTracking approach, isGuaranteedNotToBeUndefOrPoison has been updated to confirm that if an op can't create undef/poison and its operands are guaranteed not to be undef/poison - then its not undef/poison. This is just for the generic opcodes - target specific opcodes will need to do this manually just in case they have some special cases.

Differential Revision: https://reviews.llvm.org/D132333
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
llvm/test/CodeGen/X86/freeze-binary.ll