[all-commits] [llvm/llvm-project] 1896fb: [SelectionDAG] Assume that a GlobalAlias may alias...

Björn Pettersson via All-commits all-commits at lists.llvm.org
Tue Oct 5 03:17:10 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 1896fb2cfffcf120eb28cefb67ac3d56035adc43
      https://github.com/llvm/llvm-project/commit/1896fb2cfffcf120eb28cefb67ac3d56035adc43
  Author: Bjorn Pettersson <bjorn.a.pettersson at ericsson.com>
  Date:   2021-10-05 (Tue, 05 Oct 2021)

  Changed paths:
    M llvm/lib/CodeGen/SelectionDAG/SelectionDAGAddressAnalysis.cpp
    A llvm/test/CodeGen/X86/pr51878_computeAliasing.ll
    M llvm/unittests/CodeGen/SelectionDAGAddressAnalysisTest.cpp

  Log Message:
  -----------
  [SelectionDAG] Assume that a GlobalAlias may alias other global values

This fixes a bug detected in DAGCombiner when using global alias
variables. Here is an example:
  @foo = global i16 0, align 1
  @aliasFoo = alias i16, i16 * @foo
  define i16 @bar() {
    ...
    store i16 7, i16 * @foo, align 1
    store i16 8, i16 * @aliasFoo, align 1
    ...
  }

BaseIndexOffset::computeAliasing would incorrectly derive NoAlias
for the two accesses in the example above, resulting in DAGCombiner
miscompiles.

This patch fixes the problem by a defensive approach letting
BaseIndexOffset::computeAliasing return false, i.e. that the aliasing
couldn't be determined, when comparing two global values and at least
one is a GlobalAlias. In the future we might improve this with a
deeper analysis to look at the aliasee for the GlobalAlias etc. But
that is a bit more complicated considering that we could have
'local_unnamed_addr' and situations with several 'alias' variables.

Fixes PR51878.

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


  Commit: 8ed0e6b2cf941aa29628acdf718e82618d60bfc0
      https://github.com/llvm/llvm-project/commit/8ed0e6b2cf941aa29628acdf718e82618d60bfc0
  Author: Bjorn Pettersson <bjorn.a.pettersson at ericsson.com>
  Date:   2021-10-05 (Tue, 05 Oct 2021)

  Changed paths:
    M llvm/lib/CodeGen/SelectionDAG/SelectionDAGAddressAnalysis.cpp
    M llvm/unittests/CodeGen/SelectionDAGAddressAnalysisTest.cpp

  Log Message:
  -----------
  [SelectionDAG] Replace error prone index check in BaseIndexOffset::computeAliasing

Deriving NoAlias based on having the same index in two BaseIndexOffset
expressions seemed weird (and as shown in the added unittest the
correctness of doing so depended on undocumented pre-conditions that
the user of BaseIndexOffset::computeAliasing would need to take care
of.

This patch removes the code that dereived NoAlias based on indices
being the same. As a compensation, to avoid regressions/diffs in
various lit test, we also add a new check. The new check derives
NoAlias in case the two base pointers are based on two different
GlobalValue:s (neither of them being a GlobalAlias).

Reviewed By: niravd

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


Compare: https://github.com/llvm/llvm-project/compare/d009f6e51cae...8ed0e6b2cf94


More information about the All-commits mailing list