SelectionDAG: Fix bug in ClusterNeighboringLoads
authorNicolai Hähnle <nicolai.haehnle@amd.com>
Fri, 7 Feb 2020 21:08:36 +0000 (22:08 +0100)
committerNicolai Hähnle <nicolai.haehnle@amd.com>
Wed, 12 Feb 2020 08:12:55 +0000 (09:12 +0100)
commit07a5b849f7bcd4b99080298e93d05651aaaf4dcb
tree06ec838196e99c281ebe086a58df5194e93b8a40
parent572fc8974277e5def25029219daec20d08f85030
SelectionDAG: Fix bug in ClusterNeighboringLoads

Summary:
The method attempts to find loads that can be legally clustered by
looking for loads consuming the same chain glue token.

However, the old code looks at _all_ users of values produced by the
chain node -- including uses of the loaded/returned value of volatile
loads or atomics. This could lead to circular dependencies which then
failed during scheduling.

With this change, we filter out users by getResNo, i.e. by which
SDValue value they use, to ensure that we only look at users of the
chain glue token.

This appears to be a rather old bug, which is perhaps surprising.
However, the test case is actually quite fragile (i.e., it is hidden
by fairly small changes), and the test _must_ use volatile loads for
the bug to manifest.

Reviewers: arsenm, bogner, craig.topper, foad

Subscribers: MatzeB, jvesely, wdng, hiraditya, javed.absar, jfb, kerbowa, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D74253
llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp
llvm/test/CodeGen/AMDGPU/bug-sdag-scheduler-cycle.ll [new file with mode: 0644]