Skip to content

Commit a086085

Browse files
committed
[InstCombine] Add test extracting element in a loop, and move vec_extract_var_elt-inseltpoison.ll to vec_extract_var_elt.ll
1 parent 4a8dd49 commit a086085

File tree

2 files changed

+92
-33
lines changed

2 files changed

+92
-33
lines changed

llvm/test/Transforms/InstCombine/vec_extract_var_elt-inseltpoison.ll

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 92 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
12
; RUN: opt < %s -passes=instcombine -S | FileCheck %s
23

3-
define void @test (float %b, ptr %p) {
4-
; CHECK: extractelement
5-
; CHECK: fptosi
4+
define void @test_undef (float %b, ptr %p) {
5+
; CHECK-LABEL: define void @test_undef(
6+
; CHECK-SAME: float [[B:%.*]], ptr [[P:%.*]]) {
7+
; CHECK-NEXT: [[TMP1:%.*]] = load <8 x float>, ptr [[P]], align 32
8+
; CHECK-NEXT: [[TMP2:%.*]] = fptosi float [[B]] to i32
9+
; CHECK-NEXT: [[TMP3:%.*]] = add i32 [[TMP2]], -2
10+
; CHECK-NEXT: [[TMP4:%.*]] = extractelement <8 x float> [[TMP1]], i32 [[TMP3]]
11+
; CHECK-NEXT: [[TMP5:%.*]] = fptosi float [[TMP4]] to i32
12+
; CHECK-NEXT: [[TMP6:%.*]] = insertelement <8 x i32> <i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 poison>, i32 [[TMP5]], i64 7
13+
; CHECK-NEXT: [[TMP7:%.*]] = sitofp <8 x i32> [[TMP6]] to <8 x float>
14+
; CHECK-NEXT: store <8 x float> [[TMP7]], ptr [[P]], align 32
15+
; CHECK-NEXT: ret void
16+
;
617
%1 = load <8 x float> , ptr %p
718
%2 = bitcast <8 x float> %1 to <8 x i32>
819
%3 = bitcast <8 x i32> %2 to <8 x float>
@@ -13,14 +24,88 @@ define void @test (float %b, ptr %p) {
1324
%7 = insertelement <8 x i32> undef, i32 %6, i32 7
1425
%8 = sitofp <8 x i32> %7 to <8 x float>
1526
store <8 x float> %8, ptr %p
16-
ret void
27+
ret void
28+
}
29+
30+
define void @test_poison (float %b, ptr %p) {
31+
; CHECK-LABEL: define void @test_poison(
32+
; CHECK-SAME: float [[B:%.*]], ptr [[P:%.*]]) {
33+
; CHECK-NEXT: [[TMP1:%.*]] = load <8 x float>, ptr [[P]], align 32
34+
; CHECK-NEXT: [[TMP2:%.*]] = fptosi float [[B]] to i32
35+
; CHECK-NEXT: [[TMP3:%.*]] = add i32 [[TMP2]], -2
36+
; CHECK-NEXT: [[TMP4:%.*]] = extractelement <8 x float> [[TMP1]], i32 [[TMP3]]
37+
; CHECK-NEXT: [[TMP5:%.*]] = fptosi float [[TMP4]] to i32
38+
; CHECK-NEXT: [[TMP6:%.*]] = insertelement <8 x i32> poison, i32 [[TMP5]], i64 7
39+
; CHECK-NEXT: [[TMP7:%.*]] = sitofp <8 x i32> [[TMP6]] to <8 x float>
40+
; CHECK-NEXT: store <8 x float> [[TMP7]], ptr [[P]], align 32
41+
; CHECK-NEXT: ret void
42+
;
43+
%1 = load <8 x float> , ptr %p
44+
%2 = bitcast <8 x float> %1 to <8 x i32>
45+
%3 = bitcast <8 x i32> %2 to <8 x float>
46+
%a = fptosi <8 x float> %3 to <8 x i32>
47+
%4 = fptosi float %b to i32
48+
%5 = add i32 %4, -2
49+
%6 = extractelement <8 x i32> %a, i32 %5
50+
%7 = insertelement <8 x i32> poison, i32 %6, i32 7
51+
%8 = sitofp <8 x i32> %7 to <8 x float>
52+
store <8 x float> %8, ptr %p
53+
ret void
1754
}
1855

1956
; PR18600
20-
define i32 @test2(i32 %i) {
57+
define i32 @test_bitcast(i32 %i) {
58+
; CHECK-LABEL: define i32 @test_bitcast(
59+
; CHECK-SAME: i32 [[I:%.*]]) {
60+
; CHECK-NEXT: [[E:%.*]] = extractelement <4 x i32> <i32 1, i32 0, i32 2, i32 0>, i32 [[I]]
61+
; CHECK-NEXT: ret i32 [[E]]
62+
;
2163
%e = extractelement <4 x i32> bitcast (<2 x i64> <i64 1, i64 2> to <4 x i32>), i32 %i
2264
ret i32 %e
65+
}
66+
67+
declare void @use(i32)
68+
69+
define void @test_loop(<4 x float> %in) {
70+
; CHECK-LABEL: define void @test_loop(
71+
; CHECK-SAME: <4 x float> [[IN:%.*]]) {
72+
; CHECK-NEXT: [[ENTRY:.*]]:
73+
; CHECK-NEXT: [[R:%.*]] = call <4 x float> @llvm.x86.sse41.round.ps(<4 x float> [[IN]], i32 9)
74+
; CHECK-NEXT: br label %[[LOOP:.*]]
75+
; CHECK: [[LOOP]]:
76+
; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, %[[ENTRY]] ], [ [[NEXT:%.*]], %[[LATCH:.*]] ]
77+
; CHECK-NEXT: [[COND:%.*]] = icmp samesign ult i32 [[I]], 4
78+
; CHECK-NEXT: br i1 [[COND]], label %[[BODY:.*]], label %[[DONE:.*]]
79+
; CHECK: [[BODY]]:
80+
; CHECK-NEXT: [[TMP0:%.*]] = extractelement <4 x float> [[R]], i32 [[I]]
81+
; CHECK-NEXT: [[ELEM:%.*]] = fptosi float [[TMP0]] to i32
82+
; CHECK-NEXT: call void @use(i32 [[ELEM]])
83+
; CHECK-NEXT: br label %[[LATCH]]
84+
; CHECK: [[LATCH]]:
85+
; CHECK-NEXT: [[NEXT]] = add nuw nsw i32 [[I]], 1
86+
; CHECK-NEXT: br label %[[LOOP]]
87+
; CHECK: [[DONE]]:
88+
; CHECK-NEXT: ret void
89+
;
90+
entry:
91+
%r = call <4 x float> @llvm.x86.sse41.round.ps(<4 x float> %in, i32 9)
92+
%vi = fptosi <4 x float> %r to <4 x i32>
93+
br label %loop
94+
95+
loop:
96+
%i = phi i32 [ 0, %entry ], [ %next, %latch ]
97+
%cond = icmp ult i32 %i, 4
98+
br i1 %cond, label %body, label %done
99+
100+
body:
101+
%elem = extractelement <4 x i32> %vi, i32 %i
102+
call void @use(i32 %elem)
103+
br label %latch
104+
105+
latch:
106+
%next = add i32 %i, 1
107+
br label %loop
23108

24-
; CHECK-LABEL: @test2
25-
; CHECK: extractelement
109+
done:
110+
ret void
26111
}

0 commit comments

Comments
 (0)