[PATCH] D30123: [InstCombine] shrink truncated splat shuffle

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 7 10:15:51 PST 2017


Yes - sorry about that. I don't usually check-clang with an optimizer patch
(because I shouldn't have to...). But there's a clang test
(tools/clang/test/CodeGen/zvector.c) that depends on the optimizer, so it
needs to be fixed/hacked because the output changed.

I reverted my commit while I look at it :
rL297166 <https://reviews.llvm.org/rL297166>


On Tue, Mar 7, 2017 at 11:08 AM, Zachary Turner <zturner at google.com> wrote:

> Are you looking into all the failures?
>
> http://lab.llvm.org:8011/builders/clang-cmake-aarch64-quick/builds/4406
>
> On Tue, Mar 7, 2017 at 8:30 AM Sanjay Patel via Phabricator via
> llvm-commits <llvm-commits at lists.llvm.org> wrote:
>
>> This revision was automatically updated to reflect the committed changes.
>> Closed by commit rL297155: [InstCombine] shrink truncated splat shuffle
>> (authored by spatel).
>>
>> Changed prior to commit:
>>   https://reviews.llvm.org/D30123?vs=89025&id=90857#toc
>>
>> Repository:
>>   rL LLVM
>>
>> https://reviews.llvm.org/D30123
>>
>> Files:
>>   llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp
>>   llvm/trunk/test/Transforms/InstCombine/trunc.ll
>>
>>
>> Index: llvm/trunk/test/Transforms/InstCombine/trunc.ll
>> ===================================================================
>> --- llvm/trunk/test/Transforms/InstCombine/trunc.ll
>> +++ llvm/trunk/test/Transforms/InstCombine/trunc.ll
>> @@ -478,28 +478,26 @@
>>    ret <4 x i8> %trunc
>>  }
>>
>> -; FIXME:
>>  ; trunc (shuffle X, undef, SplatMask) --> shuffle (trunc X), undef,
>> SplatMask
>>
>>  define <4 x i8> @wide_splat1(<4 x i32> %x) {
>>  ; CHECK-LABEL: @wide_splat1(
>> -; CHECK-NEXT:    [[SHUF:%.*]] = shufflevector <4 x i32> %x, <4 x i32>
>> undef, <4 x i32> <i32 2, i32 2, i32 2, i32 2>
>> -; CHECK-NEXT:    [[TRUNC:%.*]] = trunc <4 x i32> [[SHUF]] to <4 x i8>
>> +; CHECK-NEXT:    [[TMP1:%.*]] = trunc <4 x i32> %x to <4 x i8>
>> +; CHECK-NEXT:    [[TRUNC:%.*]] = shufflevector <4 x i8> [[TMP1]], <4 x
>> i8> undef, <4 x i32> <i32 2, i32 2, i32 2, i32 2>
>>  ; CHECK-NEXT:    ret <4 x i8> [[TRUNC]]
>>  ;
>>    %shuf = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> <i32 2,
>> i32 2, i32 2, i32 2>
>>    %trunc = trunc <4 x i32> %shuf to <4 x i8>
>>    ret <4 x i8> %trunc
>>  }
>>
>> -; FIXME:
>>  ; Test weird types.
>>  ; trunc (shuffle X, undef, SplatMask) --> shuffle (trunc X), undef,
>> SplatMask
>>
>>  define <3 x i31> @wide_splat2(<3 x i33> %x) {
>>  ; CHECK-LABEL: @wide_splat2(
>> -; CHECK-NEXT:    [[SHUF:%.*]] = shufflevector <3 x i33> %x, <3 x i33>
>> undef, <3 x i32> <i32 1, i32 1, i32 1>
>> -; CHECK-NEXT:    [[TRUNC:%.*]] = trunc <3 x i33> [[SHUF]] to <3 x i31>
>> +; CHECK-NEXT:    [[TMP1:%.*]] = trunc <3 x i33> %x to <3 x i31>
>> +; CHECK-NEXT:    [[TRUNC:%.*]] = shufflevector <3 x i31> [[TMP1]], <3 x
>> i31> undef, <3 x i32> <i32 1, i32 1, i32 1>
>>  ; CHECK-NEXT:    ret <3 x i31> [[TRUNC]]
>>  ;
>>    %shuf = shufflevector <3 x i33> %x, <3 x i33> undef, <3 x i32> <i32 1,
>> i32 1, i32 1>
>> Index: llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp
>> ===================================================================
>> --- llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp
>> +++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp
>> @@ -463,6 +463,23 @@
>>    return BinaryOperator::Create(LogicOp->getOpcode(), NarrowOp0,
>> NarrowC);
>>  }
>>
>> +/// Try to narrow the width of a splat shuffle. This could be
>> generalized to any
>> +/// shuffle with a constant operand, but we limit the transform to avoid
>> +/// creating a shuffle type that targets may not be able to lower
>> effectively.
>> +static Instruction *shrinkSplatShuffle(TruncInst &Trunc,
>> +                                       InstCombiner::BuilderTy &Builder)
>> {
>> +  auto *Shuf = dyn_cast<ShuffleVectorInst>(Trunc.getOperand(0));
>> +  if (Shuf && Shuf->hasOneUse() && isa<UndefValue>(Shuf->getOperand(1))
>> &&
>> +      Shuf->getMask()->getSplatValue()) {
>> +    // trunc (shuf X, Undef, SplatMask) --> shuf (trunc X), Undef,
>> SplatMask
>> +    Constant *NarrowUndef = UndefValue::get(Trunc.getType());
>> +    Value *NarrowOp = Builder.CreateTrunc(Shuf->getOperand(0),
>> Trunc.getType());
>> +    return new ShuffleVectorInst(NarrowOp, NarrowUndef, Shuf->getMask());
>> +  }
>> +
>> +  return nullptr;
>> +}
>> +
>>  Instruction *InstCombiner::visitTrunc(TruncInst &CI) {
>>    if (Instruction *Result = commonCastTransforms(CI))
>>      return Result;
>> @@ -554,6 +571,9 @@
>>    if (Instruction *I = shrinkBitwiseLogic(CI))
>>      return I;
>>
>> +  if (Instruction *I = shrinkSplatShuffle(CI, *Builder))
>> +    return I;
>> +
>>    if (Src->hasOneUse() && isa<IntegerType>(SrcTy) &&
>>        shouldChangeType(SrcTy, DestTy)) {
>>      // Transform "trunc (shl X, cst)" -> "shl (trunc X), cst" so long as
>> the
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170307/ffa143a9/attachment.html>


More information about the llvm-commits mailing list