<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jul 3, 2014 at 4:24 AM, Andrea Di Biagio <span dir="ltr"><<a href="mailto:andrea.dibiagio@gmail.com" target="_blank">andrea.dibiagio@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div id=":b4m" class="a3s" style="overflow:hidden">With your change, if we widen the vector type, then we introduce more<br>

elements in the vector; that means, if the type was used by a<br>
ISD::SHL/SRL/SRA, we are potentially introducing a longer chain of<br>
scalar shifts.<br>
<br>
Example 1.<br>
-----<br>
define <2 x i32> @test1( <2 x i32> %A, <2 x i32> %B) {<br>
  %1 = lshr <2 x i32> %A, %B<br>
  ret < 2 x i32> %1<br>
}<br>
<br>
[Without AVX2]<br>
Before this change, type <2 x i32> was promoted to <2 x i64>. The<br>
logical shift was then scalarized into a sequence of  2 'shrq'.<br>
If we widen the vector from <2 x i32> to <4 x i32> the shift is now<br>
scalarized into a worse longer sequence of 4 'shrl'.<br>
<br>
Example 2.<br>
----<br>
<br>
define <2 x i32> @test2( <2 x i32> %A, <2 x i32> %B) {<br>
  %1 = ashr <2 x i32> %A, %B<br>
  ret < 2 x i32> %1<br>
}<br>
<br>
[Without AVX2]<br>
Similar to Example 1.<br>
We end up with a longer scalar sequence of 'sarl' instructions.<br></div></blockquote></div><br></div><div class="gmail_extra">We shouldn't end up with these extra shifts, because the "widened" inputs are undef, and the DAG combiner should get a chance to delete them. If it doesn't today, I think that's the bug and it should be fixed.</div>
<div class="gmail_extra"><br></div><div class="gmail_extra"><br></div><div class="gmail_extra">However, currently, it may be hard to see this for the noise. Currently, the vector operation legalization framework doesn't even really attempt to do an intelligent job of legalizing vector operations when doing so requires something other than naive scalarization. I'm working on that right now, but it's a pretty substantial change -- it essentially is implementing promotion rules from the type legalization engine in the vector operation legalization engine.</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">There are essentially piles of places right now where widening causes us to blindly scalarize. =/ But I agree with you that if we can fix those (and fix the few other oddities like the shift one) the results should be quite a bit nicer.</div>
</div>