<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - Miscompile with aliased variable. DAGCombiner doesn't realize aliased variable alias?"
href="https://bugs.llvm.org/show_bug.cgi?id=51878">51878</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Miscompile with aliased variable. DAGCombiner doesn't realize aliased variable alias?
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Common Code Generator Code
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>mikael.holmen@ericsson.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=25264" name="attach_25264" title="bbi-60286.ll reproducer">attachment 25264</a> <a href="attachment.cgi?id=25264&action=edit" title="bbi-60286.ll reproducer">[details]</a></span>
bbi-60286.ll reproducer
llvm commit: 0dc461441eed
Reproduce with:
llc -O1 -o - bbi-60286.ll
Result:
movq aliasVar@GOTPCREL(%rip), %rax
movw $5, (%rax)
movq cmVar@GOTPCREL(%rip), %rax
movw $7, (%rax)
movw $5, %ax
retq
Since aliasVar is just an alias of cmVar I would have expected the return value
from the function to be 7, but it is 5.
During ISel we have
Initial selection DAG: %bb.0 'main:entry'
SelectionDAG has 14 nodes:
t3: i64 = Constant<0>
t0: ch = EntryToken
t5: ch = store<(store (s16) into @aliasVar, align 1)> t0, Constant:i16<5>,
GlobalAddress:i64<i16* @aliasVar> 0, undef:i64
t8: ch = store<(store (s16) into @cmVar, align 1)> t5, Constant:i16<7>,
GlobalAddress:i64<i16* @cmVar> 0, undef:i64
t9: i16,ch = load<(load (s16) from @aliasVar, align 1)> t8,
GlobalAddress:i64<i16* @aliasVar> 0, undef:i64
t12: ch,glue = CopyToReg t8, Register:i16 $ax, t9
t13: ch = X86ISD::RET_FLAG t12, TargetConstant:i32<0>, Register:i16 $ax,
t12:1
which I think is ok, the two stores and then the load are chained together and
thus ordered, but then we get
Optimized lowered selection DAG: %bb.0 'main:entry'
SelectionDAG has 13 nodes:
t0: ch = EntryToken
t5: ch = store<(store (s16) into @aliasVar, align 1)> t0,
Constant:i16<5>, GlobalAddress:i64<i16* @aliasVar> 0, undef:i64
t16: ch = store<(store (s16) into @cmVar, align 1)> t0, Constant:i16<7>,
GlobalAddress:i64<i16* @cmVar> 0, undef:i64
t17: ch = TokenFactor t5, t16
t12: ch,glue = CopyToReg t17, Register:i16 $ax, Constant:i16<5>
t13: ch = X86ISD::RET_FLAG t12, TargetConstant:i32<0>, Register:i16 $ax,
t12:1
and now the stores are not ordered anymore, and the load has been removed and
the constant 5 is returned instead.
Is looks like the DAGCombiner doesn't realize aliasVar is actually the same
thing as cmVar.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>