1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 19:23:23 +01:00
llvm-mirror/test/Transforms/InstCombine/broadcast.ll
Florian Hahn 75fa314f27 [InstCombine] Fold insert sequence if first ins has multiple users.
Summary:
If the first insertelement instruction has multiple users and inserts at
position 0, we can re-use this instruction when folding a chain of
insertelement instructions. As we need to generate the first
insertelement instruction anyways, this should be a strict improvement.

We could get rid of the restriction of inserting at position 0 by
creating a different shufflemask, but it is probably worth to keep the
first insertelement instruction with position 0, as this is easier to do
efficiently than at other positions I think.

Reviewers: grosser, mkuper, fpetrogalli, efriedma

Reviewed By: fpetrogalli

Subscribers: gareevroman, llvm-commits

Differential Revision: https://reviews.llvm.org/D37064

llvm-svn: 312110
2017-08-30 10:54:21 +00:00

138 lines
5.4 KiB
LLVM

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -instcombine -S < %s | FileCheck %s
; CHECK-LABEL: good1
; CHECK: %[[INS:.*]] = insertelement <4 x float> undef, float %arg, i32 0
; CHECK-NEXT: %[[BCAST:.*]] = shufflevector <4 x float> %[[INS]], <4 x float> undef, <4 x i32> zeroinitializer
; CHECK-NEXT: ret <4 x float> %[[BCAST]]
define <4 x float> @good1(float %arg) {
%tmp = insertelement <4 x float> undef, float %arg, i32 0
%tmp4 = insertelement <4 x float> %tmp, float %arg, i32 1
%tmp5 = insertelement <4 x float> %tmp4, float %arg, i32 2
%tmp6 = insertelement <4 x float> %tmp5, float %arg, i32 3
ret <4 x float> %tmp6
}
; CHECK-LABEL: good2
; CHECK: %[[INS:.*]] = insertelement <4 x float> undef, float %arg, i32 0
; CHECK-NEXT: %[[BCAST:.*]] = shufflevector <4 x float> %[[INS]], <4 x float> undef, <4 x i32> zeroinitializer
; CHECK-NEXT: ret <4 x float> %[[BCAST]]
define <4 x float> @good2(float %arg) {
%tmp = insertelement <4 x float> undef, float %arg, i32 1
%tmp4 = insertelement <4 x float> %tmp, float %arg, i32 2
%tmp5 = insertelement <4 x float> %tmp4, float %arg, i32 0
%tmp6 = insertelement <4 x float> %tmp5, float %arg, i32 3
ret <4 x float> %tmp6
}
; CHECK-LABEL: good3
; CHECK: %[[INS:.*]] = insertelement <4 x float> undef, float %arg, i32 0
; CHECK-NEXT: %[[BCAST:.*]] = shufflevector <4 x float> %[[INS]], <4 x float> undef, <4 x i32> zeroinitializer
; CHECK-NEXT: ret <4 x float> %[[BCAST]]
define <4 x float> @good3(float %arg) {
%tmp = insertelement <4 x float> zeroinitializer, float %arg, i32 0
%tmp4 = insertelement <4 x float> %tmp, float %arg, i32 1
%tmp5 = insertelement <4 x float> %tmp4, float %arg, i32 2
%tmp6 = insertelement <4 x float> %tmp5, float %arg, i32 3
ret <4 x float> %tmp6
}
; CHECK-LABEL: good4
; CHECK: %[[INS:.*]] = insertelement <4 x float> undef, float %arg, i32 0
; CHECK-NEXT: %[[ADD:.*]] = fadd <4 x float> %[[INS]], %[[INS]]
; CHECK-NEXT: %[[BCAST:.*]] = shufflevector <4 x float> %[[ADD]], <4 x float> undef, <4 x i32> zeroinitializer
; CHECK-NEXT: ret <4 x float> %[[BCAST]]
define <4 x float> @good4(float %arg) {
%tmp = insertelement <4 x float> zeroinitializer, float %arg, i32 0
%tmp4 = insertelement <4 x float> %tmp, float %arg, i32 1
%tmp5 = insertelement <4 x float> %tmp4, float %arg, i32 2
%tmp6 = insertelement <4 x float> %tmp5, float %arg, i32 3
%tmp7 = fadd <4 x float> %tmp6, %tmp6
ret <4 x float> %tmp7
}
; CHECK-LABEL: @good5(
; CHECK-NEXT: %ins1 = insertelement <4 x float> undef, float %v, i32 0
; CHECK-NEXT: %a1 = fadd <4 x float> %ins1, %ins1
; CHECK-NEXT: %ins4 = shufflevector <4 x float> %ins1, <4 x float> undef, <4 x i32> zeroinitializer
; CHECK-NEXT: %res = fadd <4 x float> %a1, %ins4
; CHECK-NEXT: ret <4 x float> %res
define <4 x float> @good5(float %v) {
%ins1 = insertelement <4 x float> undef, float %v, i32 0
%a1 = fadd <4 x float> %ins1, %ins1
%ins2 = insertelement<4 x float> %ins1, float %v, i32 1
%ins3 = insertelement<4 x float> %ins2, float %v, i32 2
%ins4 = insertelement<4 x float> %ins3, float %v, i32 3
%res = fadd <4 x float> %a1, %ins4
ret <4 x float> %res
}
; CHECK-LABEL: bad1
; CHECK-NOT: shufflevector
define <4 x float> @bad1(float %arg) {
%tmp = insertelement <4 x float> undef, float %arg, i32 1
%tmp4 = insertelement <4 x float> %tmp, float %arg, i32 1
%tmp5 = insertelement <4 x float> %tmp4, float %arg, i32 2
%tmp6 = insertelement <4 x float> %tmp5, float %arg, i32 3
ret <4 x float> %tmp6
}
; CHECK-LABEL: bad2
; CHECK-NOT: shufflevector
define <4 x float> @bad2(float %arg) {
%tmp = insertelement <4 x float> undef, float %arg, i32 0
%tmp5 = insertelement <4 x float> %tmp, float %arg, i32 2
%tmp6 = insertelement <4 x float> %tmp5, float %arg, i32 3
ret <4 x float> %tmp6
}
; CHECK-LABEL: bad3
; CHECK-NOT: shufflevector
define <4 x float> @bad3(float %arg, float %arg2) {
%tmp = insertelement <4 x float> undef, float %arg, i32 0
%tmp4 = insertelement <4 x float> %tmp, float %arg2, i32 1
%tmp5 = insertelement <4 x float> %tmp4, float %arg, i32 2
%tmp6 = insertelement <4 x float> %tmp5, float %arg, i32 3
ret <4 x float> %tmp6
}
; CHECK-LABEL: bad4
; CHECK-NOT: shufflevector
define <1 x float> @bad4(float %arg) {
%tmp = insertelement <1 x float> undef, float %arg, i32 0
ret <1 x float> %tmp
}
; CHECK-LABEL: bad5
; CHECK-NOT: shufflevector
define <4 x float> @bad5(float %arg) {
%tmp = insertelement <4 x float> undef, float %arg, i32 0
%tmp4 = insertelement <4 x float> %tmp, float %arg, i32 1
%tmp5 = insertelement <4 x float> %tmp4, float %arg, i32 2
%tmp6 = insertelement <4 x float> %tmp5, float %arg, i32 3
%tmp7 = fadd <4 x float> %tmp6, %tmp4
ret <4 x float> %tmp7
}
; CHECK-LABEL: bad6
; CHECK-NOT: shufflevector
define <4 x float> @bad6(float %arg, i32 %k) {
%tmp = insertelement <4 x float> undef, float %arg, i32 0
%tmp4 = insertelement <4 x float> %tmp, float %arg, i32 1
%tmp5 = insertelement <4 x float> %tmp4, float %arg, i32 %k
%tmp6 = insertelement <4 x float> %tmp5, float %arg, i32 3
ret <4 x float> %tmp6
}
; CHECK-LABEL: @bad7(
; CHECK-NOT: shufflevector
define <4 x float> @bad7(float %v) {
%ins1 = insertelement <4 x float> undef, float %v, i32 1
%a1 = fadd <4 x float> %ins1, %ins1
%ins2 = insertelement<4 x float> %ins1, float %v, i32 2
%ins3 = insertelement<4 x float> %ins2, float %v, i32 3
%ins4 = insertelement<4 x float> %ins3, float %v, i32 0
%res = fadd <4 x float> %a1, %ins4
ret <4 x float> %res
}