xref: /llvm-project/llvm/test/CodeGen/X86/pr51878_computeAliasing.ll (revision 2f448bf509432c1a19ec46ab8cbc7353c03c6280)
1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2; RUN: llc -O1 -mtriple i686-unknown-linux-gnu -o - %s | FileCheck %s
3
4@foo = global i16 0, align 1
5@aliasFoo = alias i16, ptr @foo
6@bar = global i16 0, align 1
7
8; This used to miscompile due to not realizing that the store to @aliasFoo
9; clobbered @foo (see PR51878).
10;
11; With some improvements to codegen it should be possible to detect that @foo
12; and @aliasFoo are aliases, and that @aliasFoo isn't aliasing with @bar. So
13; ideally we would end up with three movw instructions here. Running opt
14; before llc on this test case would take care of that, but llc is not smart
15; enough to deduce that itself yet.
16define i16 @main() {
17; CHECK-LABEL: main:
18; CHECK:       # %bb.0: # %entry
19; CHECK-NEXT:    movw $1, foo
20; CHECK-NEXT:    movw $2, bar
21; CHECK-NEXT:    movw $4, aliasFoo
22; CHECK-NEXT:    movzwl foo, %eax
23; CHECK-NEXT:    addw bar, %ax
24; CHECK-NEXT:    retl
25entry:
26  store i16 1, ptr @foo
27  store i16 2, ptr @bar
28  store i16 4, ptr @aliasFoo
29  %foo = load i16, ptr @foo
30  %bar = load i16, ptr @bar
31  %res = add i16 %foo, %bar
32  ret i16 %res
33}
34