This patch allows simplification:
BinOp(shuffle(v1), shuffle(v2)) -> shuffle(BinOp(v1, v2))
if both shuffles use the same mask, and both shuffle within a single vector.
Differential D3525
Reorder shuffle and binary operation. sepavloff on Apr 27 2014, 9:46 AM. Authored by
Details This patch allows simplification: BinOp(shuffle(v1), shuffle(v2)) -> shuffle(BinOp(v1, v2)) if both shuffles use the same mask, and both shuffle within a single vector.
Diff Detail Event TimelineComment Actions Updated patch, added new pattern. With this patch instcombiner tries making transformation like: BinOp(shuffle(v1), const1) -> shuffle(BinOp(V1, const2)) This reordering allows removal of extra shuffles, for instance the code: %t1 = shufflevector <4 x i32> %v, <4 x i32> undef, <4 x i32> <i32 3, i32 2, i32 1, i32 0> %t2 = mul <4 x i32> %t1, %t1 %r = shufflevector <4 x i32> %t2, <4 x i32> undef, <4 x i32> <i32 3, i32 2, i32 1, i32 0> transforms to: %1 = mul <4 x i32> %v, %v Comment Actions I think this is good now. Adding nadav to make sure I didn't miss some shufflevector lowering issue. Comment Actions Thank you for review! --Serge 2014-05-10 0:42 GMT+07:00 Benjamin Kramer <benny.kra@gmail.com>:
Comment Actions I did not review the code carefully but I think it looks fine. We are not generating new shuffle masks so there should not be any lowering problems. Comment Actions Thank you for advice and detailed explanation! --Serge 2014-05-10 1:17 GMT+07:00 Andrea Di Biagio <Andrea_DiBiagio@sn.scee.net>:
Comment Actions Hi Serge, It seems that your patch introduces a bug when two shuffles have different Thanks,
{
Comment Actions Hi Serge, It seems there is another bug. Also see http://llvm.org/bugs/show_bug.cgi?id=19717. Thanks, Comment Actions Hi Serge, It seems that there is another bug http://llvm.org/bugs/show_bug.cgi?id=19730. Thanks,
ARM Limited, Registered office 110 Fulbourn Road, Cambridge CB1 9NJ, Registered in England & Wales, Company No: 2557590 Comment Actions Hi Serge, Sorry to bother you again. Thanks,
Comment Actions Hi Serge, This patch has been breaking our internal builders since Sunday - it breaks Thanks for responding so quickly to the first reported bug but we've had one Do you have any idea when you could get around to it? Cheers, James
any
Comment Actions Hi James, I regret that the fix makes you troubles. Nor llvm tests neither test-suit discovered any problems, you have a nice test suit and I am thankful to Hao for providing test cases. All reported problems were resolved in < 4 hours, did you reported the problem that is outstanding since Monday morning? Thanks, |
I might be wrong but,
wouldn't be easier in this case to simply compare the addresses of the two shuffle masks?
As far as I understand, the shuffle mask (third operand of a ShuffleVectorInst) is always a Constant; therefore, you should be able to check if two masks are equal by simply comparing their addresses. I expect that something like this should work:
cast<ShuffleVectorInst>(LHS)->getMask() == cast<ShuffleVectorInst>(RHS)->getMask().
quoting what is written in Constant.h, "two structurally equivalent constants will always have the same address". Also, "The shuffle mask operand is required to be a constant vector with either constant integer or undef values".
I hope this helps.