[llvm-bugs] [Bug 32486] New: Instcombine: shufflevector with undef mask overaggressively simplified to an undef constant?

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Apr 1 08:39:38 PDT 2017


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

            Bug ID: 32486
           Summary: Instcombine: shufflevector with undef mask
                    overaggressively simplified to an undef constant?
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: zvi.rackover at intel.com
                CC: llvm-bugs at lists.llvm.org

As of r299303, opt -instcombine will simplify the following function:

 define <4 x float> @foo(<4 x float> %a, <4 x float> %b) {
   %s = shufflevector <4 x float> %a, <4 x float> %b, <4 x i32> undef
   ret <4 x float> %s
 }

to:

 define <4 x float> @foo(<4 x float> %a, <4 x float> %b) {
   ret <4 x float> undef
 }


As Sanjay pointed out in https://reviews.llvm.org/D31525#715234:
"
Why would a shuffle with undef mask automatically return undef? For example:
shufflevector <2 x i8> <i8 42, i8 42>, <2 x i8> <i8 42, i8 42>, <2 x i32> undef

Should this be constant folded to <i8 42, i8 42> , <2 x i8> undef or something
else?
"

This kind of simplification is implemented in these locations and possibly
others:

- Explicitly in InstCombiner::visitShuffleVectorInst
- Explicitly in ConstantFoldShuffleVectorInstruction
- InstCombiner::SimplifyDemandedVectorElts will eventually return an undef
constant

The language reference says 'The element selector may be undef (meaning “don’t
care”)...'.
"don't care" can be one of:
1. Don't care what element is selected from the input vectors
2. The respective element in the result vector is undef

We may use the examples from the 'Undefined Values' section in the language
reference to reason about shuffles in the same manner do for select's:
"This set of examples shows that undefined ‘select‘ (and conditional branch)
conditions can go either way, but they have to come from one of the two
operands."

-- 
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/20170401/9429399d/attachment.html>


More information about the llvm-bugs mailing list