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
34 lines
1.1 KiB
LLVM
34 lines
1.1 KiB
LLVM
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
|
|
; RUN: llc -O1 -mtriple i686-unknown-linux-gnu -o - %s | FileCheck %s
|
|
|
|
@foo = global i16 0, align 1
|
|
@aliasFoo = alias i16, i16 * @foo
|
|
@bar = global i16 0, align 1
|
|
|
|
; This used to miscompile due to not realizing that the store to @aliasFoo
|
|
; clobbered @foo (see PR51878).
|
|
;
|
|
; With some improvements to codegen it should be possible to detect that @foo
|
|
; and @aliasFoo are aliases, and that @aliasFoo isn't aliasing with @bar. So
|
|
; ideally we would end up with three movw instructions here. Running opt
|
|
; before llc on this test case would take care of that, but llc is not smart
|
|
; enough to deduce that itself yet.
|
|
define i16 @main() {
|
|
; CHECK-LABEL: main:
|
|
; CHECK: # %bb.0: # %entry
|
|
; CHECK-NEXT: movw $1, foo
|
|
; CHECK-NEXT: movw $2, bar
|
|
; CHECK-NEXT: movw $4, aliasFoo
|
|
; CHECK-NEXT: movzwl foo, %eax
|
|
; CHECK-NEXT: addw bar, %ax
|
|
; CHECK-NEXT: retl
|
|
entry:
|
|
store i16 1, i16 * @foo
|
|
store i16 2, i16 * @bar
|
|
store i16 4, i16 * @aliasFoo
|
|
%foo = load i16, i16 * @foo
|
|
%bar = load i16, i16 * @bar
|
|
%res = add i16 %foo, %bar
|
|
ret i16 %res
|
|
}
|