[AArch64][NFC] NFC for const vector as Instruction operand (#116790)
[llvm-project.git] / llvm / test / Transforms / InstCombine / bitcast-vec-canon.ll
blobf787b3c4cc9ac25dac67db27de9b44adda228790
1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
4 define double @a(<1 x i64> %y) {
5 ; CHECK-LABEL: @a(
6 ; CHECK-NEXT:    [[BC:%.*]] = bitcast <1 x i64> [[Y:%.*]] to <1 x double>
7 ; CHECK-NEXT:    [[C:%.*]] = extractelement <1 x double> [[BC]], i64 0
8 ; CHECK-NEXT:    ret double [[C]]
10   %c = bitcast <1 x i64> %y to double
11   ret double %c
14 define i64 @b(<1 x i64> %y) {
15 ; CHECK-LABEL: @b(
16 ; CHECK-NEXT:    [[TMP1:%.*]] = extractelement <1 x i64> [[Y:%.*]], i64 0
17 ; CHECK-NEXT:    ret i64 [[TMP1]]
19   %c = bitcast <1 x i64> %y to i64
20   ret i64 %c
23 define <1 x i64> @c(double %y) {
24 ; CHECK-LABEL: @c(
25 ; CHECK-NEXT:    [[C:%.*]] = bitcast double [[Y:%.*]] to <1 x i64>
26 ; CHECK-NEXT:    ret <1 x i64> [[C]]
28   %c = bitcast double %y to <1 x i64>
29   ret <1 x i64> %c
32 define <1 x i64> @d(i64 %y) {
33 ; CHECK-LABEL: @d(
34 ; CHECK-NEXT:    [[C:%.*]] = insertelement <1 x i64> poison, i64 [[Y:%.*]], i64 0
35 ; CHECK-NEXT:    ret <1 x i64> [[C]]
37   %c = bitcast i64 %y to <1 x i64>
38   ret <1 x i64> %c
42 ; FP source is ok.
44 define <3 x i64> @bitcast_inselt_undef(double %x, i32 %idx) {
45 ; CHECK-LABEL: @bitcast_inselt_undef(
46 ; CHECK-NEXT:    [[TMP1:%.*]] = insertelement <3 x double> undef, double [[X:%.*]], i32 [[IDX:%.*]]
47 ; CHECK-NEXT:    [[I:%.*]] = bitcast <3 x double> [[TMP1]] to <3 x i64>
48 ; CHECK-NEXT:    ret <3 x i64> [[I]]
50   %xb = bitcast double %x to i64
51   %i = insertelement <3 x i64> undef, i64 %xb, i32 %idx
52   ret <3 x i64> %i
55 ; Integer source is ok; index is anything.
57 define <3 x float> @bitcast_inselt_undef_fp(i32 %x, i567 %idx) {
58 ; CHECK-LABEL: @bitcast_inselt_undef_fp(
59 ; CHECK-NEXT:    [[TMP1:%.*]] = insertelement <3 x i32> undef, i32 [[X:%.*]], i567 [[IDX:%.*]]
60 ; CHECK-NEXT:    [[I:%.*]] = bitcast <3 x i32> [[TMP1]] to <3 x float>
61 ; CHECK-NEXT:    ret <3 x float> [[I]]
63   %xb = bitcast i32 %x to float
64   %i = insertelement <3 x float> undef, float %xb, i567 %idx
65   ret <3 x float> %i
68 define <vscale x 3 x float> @bitcast_inselt_undef_vscale(i32 %x, i567 %idx) {
69 ; CHECK-LABEL: @bitcast_inselt_undef_vscale(
70 ; CHECK-NEXT:    [[TMP1:%.*]] = insertelement <vscale x 3 x i32> undef, i32 [[X:%.*]], i567 [[IDX:%.*]]
71 ; CHECK-NEXT:    [[I:%.*]] = bitcast <vscale x 3 x i32> [[TMP1]] to <vscale x 3 x float>
72 ; CHECK-NEXT:    ret <vscale x 3 x float> [[I]]
74   %xb = bitcast i32 %x to float
75   %i = insertelement <vscale x 3 x float> undef, float %xb, i567 %idx
76   ret <vscale x 3 x float> %i
79 declare void @use(i64)
81 ; Negative test - extra use prevents canonicalization
83 define <3 x i64> @bitcast_inselt_undef_extra_use(double %x, i32 %idx) {
84 ; CHECK-LABEL: @bitcast_inselt_undef_extra_use(
85 ; CHECK-NEXT:    [[XB:%.*]] = bitcast double [[X:%.*]] to i64
86 ; CHECK-NEXT:    call void @use(i64 [[XB]])
87 ; CHECK-NEXT:    [[I:%.*]] = insertelement <3 x i64> undef, i64 [[XB]], i32 [[IDX:%.*]]
88 ; CHECK-NEXT:    ret <3 x i64> [[I]]
90   %xb = bitcast double %x to i64
91   call void @use(i64 %xb)
92   %i = insertelement <3 x i64> undef, i64 %xb, i32 %idx
93   ret <3 x i64> %i
96 ; Negative test - source type must be scalar
98 define <3 x i64> @bitcast_inselt_undef_vec_src(<2 x i32> %x, i32 %idx) {
99 ; CHECK-LABEL: @bitcast_inselt_undef_vec_src(
100 ; CHECK-NEXT:    [[XB:%.*]] = bitcast <2 x i32> [[X:%.*]] to i64
101 ; CHECK-NEXT:    [[I:%.*]] = insertelement <3 x i64> undef, i64 [[XB]], i32 [[IDX:%.*]]
102 ; CHECK-NEXT:    ret <3 x i64> [[I]]
104   %xb = bitcast <2 x i32> %x to i64
105   %i = insertelement <3 x i64> undef, i64 %xb, i32 %idx
106   ret <3 x i64> %i
109 ; Reduce number of casts
111 define <2 x i64> @PR45748(double %x, double %y) {
112 ; CHECK-LABEL: @PR45748(
113 ; CHECK-NEXT:    [[TMP1:%.*]] = insertelement <2 x double> poison, double [[X:%.*]], i64 0
114 ; CHECK-NEXT:    [[TMP2:%.*]] = insertelement <2 x double> [[TMP1]], double [[Y:%.*]], i64 1
115 ; CHECK-NEXT:    [[I1:%.*]] = bitcast <2 x double> [[TMP2]] to <2 x i64>
116 ; CHECK-NEXT:    ret <2 x i64> [[I1]]
118   %xb = bitcast double %x to i64
119   %i0 = insertelement <2 x i64> undef, i64 %xb, i32 0
120   %yb = bitcast double %y to i64
121   %i1 = insertelement <2 x i64> %i0, i64 %yb, i32 1
122   ret <2 x i64> %i1