[llvm-bugs] [Bug 24922] New: InstCombine: SimplifyDemandedVectorElts wrongly analyzes select statements with ConstantExpr elements in the mask.

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Sep 24 03:03:58 PDT 2015


https://llvm.org/bugs/show_bug.cgi?id=24922

            Bug ID: 24922
           Summary: InstCombine: SimplifyDemandedVectorElts wrongly
                    analyzes select statements with ConstantExpr elements
                    in the mask.
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: andrea.dibiagio at gmail.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

Created attachment 14929
  --> https://llvm.org/bugs/attachment.cgi?id=14929&action=edit
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'.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150924/5f770de1/attachment.html>


More information about the llvm-bugs mailing list