<html>
<head>
<base href="https://llvm.org/bugs/" />
</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 --- - InstCombine: SimplifyDemandedVectorElts wrongly analyzes select statements with ConstantExpr elements in the mask."
href="https://llvm.org/bugs/show_bug.cgi?id=24922">24922</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>InstCombine: SimplifyDemandedVectorElts wrongly analyzes select statements with ConstantExpr elements in the mask.
</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>Windows NT
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Scalar Optimizations
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>andrea.dibiagio@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=14929" name="attach_14929" title="Reproducible">attachment 14929</a> <a href="attachment.cgi?id=14929&action=edit" title="Reproducible">[details]</a></span>
Reproducible
Method 'Instcombiner::SimplifyDemandedVectorElts' (file
InstCombineSimplifyDemanded.cpp) wrongly assumes that the vector elements of a
constant select mask cannot be 'ConstantExpr' values.
Example:
;;;;;;;; test.ll ;;;;;;;;;
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
define <2 x i64> @foo(<2 x i64> %invec) {
entry:
%0 = extractelement <2 x i64> bitcast (<4 x i32><i32 15, i32 15, i32 15, i32
15> to <2 x i64>), i64 0
%1 = extractelement <2 x i64> bitcast (<4 x i32><i32 15, i32 15, i32 15, i32
15> to <2 x i64>), i64 1
%2 = icmp eq i64 %0, 0
%3 = icmp eq i64 %1, 0
%4 = insertelement <2 x i1> undef, i1 %2, i32 0
%5 = insertelement <2 x i1> %4, i1 %3, i32 1
%result = select <2 x i1> %5, <2 x i64> %invec, <2 x i64> <i64 0, i64 0>
ret <2 x i64> %result
}
define <2 x i64> @bar(<2 x i64> %invec) {
entry:
%result = select <2 x i1> <i1 icmp eq (i64 extractelement (<2 x i64> bitcast
(<4 x i32><i32 15, i32 15, i32 15, i32 15> to <2 x i64>), i64 0), i64 0), i1
icmp eq (i64 extractelement (<2 x i64> bitcast (<4 x i32><i32 15, i32 0, i32
15, i32 15> to <2 x i64>), i64 1), i64 0)>, <2 x i64> %invec, <2 x i64> <i64 0,
i64 0>
ret <2 x i64> %result
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Both function @foo and @bar can be constant folded to a return of a zero
vector.
However, if we pass that code to `opt -instcombine -S -o -` we get:
define <2 x i64> @foo(<2 x i64> %invec) {
entry:
ret <2 x i64> zeroinitializer
}
define <2 x i64> @bar(<2 x i64> %invec) {
entry:
ret <2 x i64> %invec
}
If I pass '-debug' to opt, I get the following debug output:
IC: Mod = %result = select <2 x i1> <i1 icmp eq (i64 extractelement (<2 x i64>
bitcast (<4 x i32><i32 15, i32 15, i32 15, i32 15> to <2 x i64>), i64 0), i64
0), i1 icmp eq (i64 extractelement (<2 x i64> bitcast (<4 x i32><i32 15, i32 0,
i32 15, i32 15> to <2 x i64>), i64 1), i64 0)>, <2 x i64> %invec, <2 x i64>
zeroinitializer
New = %result = select <2 x i1> <i1 icmp eq (i64 extractelement (<2 x i64>
bitcast (<4 x i32><i32 15, i32 15, i32 15, i32 15> to <2 x i64>), i64 0), i64
0), i1 icmp eq (i64 extractelement (<2 x i64> bitcast (<4 x i32><i32 15, i32 0,
i32 15, i32 15> to <2 x i64>), i64 1), i64 0)>, <2 x i64> %invec, <2 x i64>
undef
So, the zero vector has been replaced with 'undef'.
Later on, the instruction combiner erases the select statement and propagates
%invec to all the users of %result.
If I run the debugger, I can see how the zero vector is replaced with 'undef'
as a result of a call to 'SimplifyDemandedVectorElts' in
'InstCombiner::visitSelectInst'.</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>