Skip to content

Commit c750658

Browse files
[NFC][InstCombine] Add tests for mult-user cast transforms
1 parent f6d6d2d commit c750658

File tree

1 file changed

+148
-0
lines changed
  • llvm/test/Transforms/InstCombine

1 file changed

+148
-0
lines changed

llvm/test/Transforms/InstCombine/cast.ll

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2238,3 +2238,151 @@ define i32 @test95(i32 %x) {
22382238
%5 = zext i8 %4 to i32
22392239
ret i32 %5
22402240
}
2241+
2242+
define i16 @test96(i16 %x, i16 %y) {
2243+
; ALL-LABEL: @test96(
2244+
; ALL-NEXT: [[ZX:%.*]] = zext i16 [[X:%.*]] to i32
2245+
; ALL-NEXT: [[ZY:%.*]] = zext i16 [[Y:%.*]] to i32
2246+
; ALL-NEXT: [[A:%.*]] = add nuw nsw i32 [[ZX]], [[ZY]]
2247+
; ALL-NEXT: [[B:%.*]] = add nuw nsw i32 [[A]], 5
2248+
; ALL-NEXT: [[C:%.*]] = mul nuw nsw i32 [[A]], 3
2249+
; ALL-NEXT: [[D:%.*]] = or i32 [[B]], [[C]]
2250+
; ALL-NEXT: [[T:%.*]] = trunc i32 [[D]] to i16
2251+
; ALL-NEXT: ret i16 [[T]]
2252+
;
2253+
%zx = zext i16 %x to i32
2254+
%zy = zext i16 %y to i32
2255+
%a = add i32 %zx, %zy
2256+
%b = add i32 %a, 5
2257+
%c = mul i32 %a, 3
2258+
%d = or i32 %b, %c
2259+
%t = trunc i32 %d to i16
2260+
ret i16 %t
2261+
}
2262+
2263+
define i16 @test97(i16 %x, i16 %y) {
2264+
; ALL-LABEL: @test97(
2265+
; ALL-NEXT: [[ZX:%.*]] = zext i16 [[X:%.*]] to i32
2266+
; ALL-NEXT: [[ZY:%.*]] = zext i16 [[Y:%.*]] to i32
2267+
; ALL-NEXT: [[A:%.*]] = add nuw nsw i32 [[ZX]], [[ZY]]
2268+
; ALL-NEXT: [[B:%.*]] = add nuw nsw i32 [[A]], 5
2269+
; ALL-NEXT: [[C:%.*]] = mul nuw nsw i32 [[A]], 3
2270+
; ALL-NEXT: [[D:%.*]] = or i32 [[B]], [[C]]
2271+
; ALL-NEXT: call void @use_i32(i32 [[A]])
2272+
; ALL-NEXT: [[T:%.*]] = trunc i32 [[D]] to i16
2273+
; ALL-NEXT: ret i16 [[T]]
2274+
;
2275+
%zx = zext i16 %x to i32
2276+
%zy = zext i16 %y to i32
2277+
%a = add i32 %zx, %zy
2278+
%b = add i32 %a, 5
2279+
%c = mul i32 %a, 3
2280+
%d = or i32 %b, %c
2281+
call void @use_i32(i32 %a)
2282+
%t = trunc i32 %d to i16
2283+
ret i16 %t
2284+
}
2285+
2286+
; expected not to narrow operations to i16 due to a loop in use chains
2287+
define i16 @test98(i16 %x, i16 %n) {
2288+
; ALL-LABEL: @test98(
2289+
; ALL-NEXT: entry:
2290+
; ALL-NEXT: [[Z:%.*]] = zext i16 [[X:%.*]] to i32
2291+
; ALL-NEXT: br label [[LOOP:%.*]]
2292+
; ALL: loop:
2293+
; ALL-NEXT: [[P:%.*]] = phi i32 [ [[Z]], [[ENTRY:%.*]] ], [ [[A:%.*]], [[LOOP]] ]
2294+
; ALL-NEXT: [[A]] = add i32 [[P]], 1
2295+
; ALL-NEXT: [[T:%.*]] = trunc i32 [[A]] to i16
2296+
; ALL-NEXT: [[COND:%.*]] = icmp ugt i16 [[N:%.*]], [[T]]
2297+
; ALL-NEXT: br i1 [[COND]], label [[LOOP]], label [[EXIT:%.*]]
2298+
; ALL: exit:
2299+
; ALL-NEXT: ret i16 [[T]]
2300+
;
2301+
entry:
2302+
%z = zext i16 %x to i32
2303+
br label %loop
2304+
2305+
loop:
2306+
%p = phi i32 [ %z, %entry ], [ %a, %loop ]
2307+
%a = add i32 %p, 1
2308+
%t = trunc i32 %a to i16
2309+
%cond = icmp ult i16 %t, %n
2310+
br i1 %cond, label %loop, label %exit
2311+
2312+
exit:
2313+
ret i16 %t
2314+
}
2315+
2316+
define i32 @test99(i32 %x, i32 %y) {
2317+
; ALL-LABEL: @test99(
2318+
; ALL-NEXT: [[TX:%.*]] = trunc i32 [[X:%.*]] to i16
2319+
; ALL-NEXT: [[TY:%.*]] = trunc i32 [[Y:%.*]] to i16
2320+
; ALL-NEXT: [[A:%.*]] = add i16 [[TX]], [[TY]]
2321+
; ALL-NEXT: [[B:%.*]] = add i16 [[A]], 5
2322+
; ALL-NEXT: [[C:%.*]] = mul i16 [[A]], 3
2323+
; ALL-NEXT: [[D:%.*]] = or i16 [[B]], [[C]]
2324+
; ALL-NEXT: [[S:%.*]] = sext i16 [[D]] to i32
2325+
; ALL-NEXT: ret i32 [[S]]
2326+
;
2327+
%tx = trunc i32 %x to i16
2328+
%ty = trunc i32 %y to i16
2329+
%a = add i16 %tx, %ty
2330+
%b = add i16 %a, 5
2331+
%c = mul i16 %a, 3
2332+
%d = or i16 %b, %c
2333+
%t = sext i16 %d to i32
2334+
ret i32 %t
2335+
}
2336+
2337+
define i32 @test100(i32 %x, i32 %y) {
2338+
; ALL-LABEL: @test100(
2339+
; ALL-NEXT: [[TX:%.*]] = trunc i32 [[X:%.*]] to i8
2340+
; ALL-NEXT: [[TY:%.*]] = trunc i32 [[Y:%.*]] to i8
2341+
; ALL-NEXT: [[A:%.*]] = add i8 [[TX]], [[TY]]
2342+
; ALL-NEXT: [[B:%.*]] = add i8 [[A]], 5
2343+
; ALL-NEXT: [[C:%.*]] = mul i8 [[A]], 3
2344+
; ALL-NEXT: [[D:%.*]] = or i8 [[B]], [[C]]
2345+
; ALL-NEXT: call void @use_i8(i8 [[A]])
2346+
; ALL-NEXT: [[T:%.*]] = sext i8 [[D]] to i32
2347+
; ALL-NEXT: ret i32 [[T]]
2348+
;
2349+
%tx = trunc i32 %x to i8
2350+
%ty = trunc i32 %y to i8
2351+
%a = add i8 %tx, %ty
2352+
%b = add i8 %a, 5
2353+
%c = mul i8 %a, 3
2354+
%d = or i8 %b, %c
2355+
call void @use_i8(i8 %a)
2356+
%t = sext i8 %d to i32
2357+
ret i32 %t
2358+
}
2359+
2360+
; expected not to extend operations to i32 due to a loop in use chains
2361+
define i32 @test101(i32 %x, i8 %n) {
2362+
; ALL-LABEL: @test101(
2363+
; ALL-NEXT: entry:
2364+
; ALL-NEXT: [[T:%.*]] = trunc i32 [[X:%.*]] to i8
2365+
; ALL-NEXT: br label [[LOOP:%.*]]
2366+
; ALL: loop:
2367+
; ALL-NEXT: [[P:%.*]] = phi i8 [ [[T]], [[ENTRY:%.*]] ], [ [[A:%.*]], [[LOOP]] ]
2368+
; ALL-NEXT: [[A]] = add i8 [[P]], 1
2369+
; ALL-NEXT: [[COND:%.*]] = icmp ult i8 [[A]], [[N:%.*]]
2370+
; ALL-NEXT: br i1 [[COND]], label [[LOOP]], label [[EXIT:%.*]]
2371+
; ALL: exit:
2372+
; ALL-NEXT: [[S:%.*]] = sext i8 [[A]] to i32
2373+
; ALL-NEXT: ret i32 [[S]]
2374+
;
2375+
entry:
2376+
%t = trunc i32 %x to i8
2377+
br label %loop
2378+
2379+
loop:
2380+
%p = phi i8 [ %t, %entry ], [ %a, %loop ]
2381+
%a = add i8 %p, 1
2382+
%cond = icmp ult i8 %a, %n
2383+
br i1 %cond, label %loop, label %exit
2384+
2385+
exit:
2386+
%s = sext i8 %a to i32
2387+
ret i32 %s
2388+
}

0 commit comments

Comments
 (0)