[SelectionDAG] Use correct boolean representation in FoldConstantArithmetic
authorBjorn Pettersson <bjorn.a.pettersson@ericsson.com>
Thu, 28 Apr 2022 16:31:05 +0000 (18:31 +0200)
committerBjorn Pettersson <bjorn.a.pettersson@ericsson.com>
Thu, 28 Apr 2022 16:42:16 +0000 (18:42 +0200)
commit3a39bb96ca812d1cbd027803112e94f701ad8687
tree173062adddfd643741d17dc6641ba0be0fc08b4e
parentf326df34bc179e41ea17d31e1ffba4a479e45589
[SelectionDAG] Use correct boolean representation in FoldConstantArithmetic

The description of SETCC says
  /// SetCC operator - This evaluates to a true value iff the condition is
  /// true.  If the result value type is not i1 then the high bits conform
  /// to getBooleanContents.

Without this patch, we sign extended the i1 to the used larger type
regardless of getBooleanContents. This resulted in miscompiles, as
shown in the attached testcase that ended up returning -1 instead of
1 when using -mattr=+v.

Fixes https://github.com/llvm/llvm-project/issues/55168

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D124618
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
llvm/test/CodeGen/RISCV/fold-vector-cmp.ll [new file with mode: 0644]