[SystemZ] Clear NW flags on an ISD::SUB when reused as comparison.
authorJonas Paulsson <paulsson@linux.vnet.ibm.com>
Thu, 9 Mar 2023 18:19:09 +0000 (19:19 +0100)
committerJonas Paulsson <paulsson@linux.vnet.ibm.com>
Tue, 14 Mar 2023 18:46:41 +0000 (19:46 +0100)
commitf8803919ad5c7e135af962efcbbe8c7c5310bbf4
tree2fd3af88ad44d290d2c40ea7d819c785158be519
parent7aec387dbec77282482aaaac692158569e923966
[SystemZ] Clear NW flags on an ISD::SUB when reused as comparison.

The SystemZ backend will try to reuse an existing subtraction of two values
whenever they are to be compared for equality. This depends on the SystemZ
subtraction instruction setting the condition code, which can also signal
overflow.

A later pass will remove the compare and reuse the CC from the subtraction
directly. However, if that subtraction has the NSW flag set it will not
include the overflow bit in the updated CC user. That was a bug which can
lead to wrong results, as shown by a csmith program.

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

Reviewed By: nikic, uweigand

Differential Revision: https://reviews.llvm.org/D145811
llvm/lib/Target/SystemZ/SystemZISelLowering.cpp
llvm/test/CodeGen/SystemZ/int-cmp-62.ll [new file with mode: 0644]