[DAGCombiner][RISCV] Make foldBinOpIntoSelect work correctly with opaque constants.
authorCraig Topper <craig.topper@sifive.com>
Sun, 23 Oct 2022 01:54:48 +0000 (18:54 -0700)
committerCraig Topper <craig.topper@sifive.com>
Sun, 23 Oct 2022 02:10:33 +0000 (19:10 -0700)
commit00816714f96505c59c236f3f0fd2eb815c57f674
tree15d84655f02dc41a26a80f0e3233b5c01b68e9df
parent2dfc49e589b27c8e6193edb0c29e963db1bd203f
[DAGCombiner][RISCV] Make foldBinOpIntoSelect work correctly with opaque constants.

The CanFoldNonConst doesn't work correctly with opaque constants
because getNode won't constant fold constants if one is opaque. Even
if the operation is AND/OR. This can lead to infinite loops.

This patch does the folding manually in the DAGCombine. Alternatively,
we could improve getNode but that seemed likely to have bigger impact
and possibly increase compile time for the additional checks. We wouldn't
want to directly constant fold because we need to preserve the opaque flag.

Fixes PR58511.

Reviewed By: spatel

Differential Revision: https://reviews.llvm.org/D136472
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/test/CodeGen/RISCV/pr58511.ll [new file with mode: 0644]