[SelectionDAG] Always intersect SDNode flags during getNode() node memoization.
authorJonas Paulsson <paulsson@linux.vnet.ibm.com>
Mon, 31 Aug 2020 11:26:36 +0000 (13:26 +0200)
committerJonas Paulsson <paulsson@linux.vnet.ibm.com>
Sat, 5 Sep 2020 08:30:38 +0000 (10:30 +0200)
commit714ceefad9b96ab3ef20913f2110883a1ad34a13
tree7703903090579665a78dd440f6ccfe7d04f4854c
parent39caf9e94091629c65038b90215e24eea47a5ce5
[SelectionDAG] Always intersect SDNode flags during getNode() node memoization.

Previously SDNodeFlags::instersectWith(Flags) would do nothing if Flags was
in an undefined state, which is very bad given that this is the default when
getNode() is called without passing an explicit SDNodeFlags argument.

This meant that if an already existing and reused node had a flag which the
second caller to getNode() did not set, that flag would remain uncleared.

This was exposed by https://bugs.llvm.org/show_bug.cgi?id=47092, where an NSW
flag was incorrectly set on an add instruction (which did in fact overflow in
one of the two original contexts), so when SystemZElimCompare removed the
compare with 0 trusting that flag, wrong-code resulted.

There is more that needs to be done in this area as discussed here:

Differential Revision: https://reviews.llvm.org/D86871

Review: Ulrich Weigand, Sanjay Patel
llvm/include/llvm/CodeGen/SelectionDAGNodes.h
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp
llvm/lib/Target/AMDGPU/AMDGPUISelLowering.h
llvm/test/CodeGen/SystemZ/fp-mul-14.ll [new file with mode: 0644]
llvm/test/CodeGen/SystemZ/int-cmp-60.ll [new file with mode: 0644]