1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -mtriple=x86_64-linux -codegenprepare -S < %s | FileCheck %s
4 declare { i64, i1 } @llvm.uadd.with.overflow.i64(i64, i64)
6 define i32 @test_01(i32* %p, i64 %len, i32 %x) {
7 ; CHECK-LABEL: @test_01(
9 ; CHECK-NEXT: br label [[LOOP:%.*]]
11 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[MATH:%.*]], [[BACKEDGE:%.*]] ], [ [[LEN:%.*]], [[ENTRY:%.*]] ]
12 ; CHECK-NEXT: [[TMP0:%.*]] = call { i64, i1 } @llvm.uadd.with.overflow.i64(i64 [[IV]], i64 1)
13 ; CHECK-NEXT: [[MATH]] = extractvalue { i64, i1 } [[TMP0]], 0
14 ; CHECK-NEXT: [[OV:%.*]] = extractvalue { i64, i1 } [[TMP0]], 1
15 ; CHECK-NEXT: br i1 [[OV]], label [[EXIT:%.*]], label [[BACKEDGE]]
17 ; CHECK-NEXT: [[SUNKADDR3:%.*]] = mul i64 [[MATH]], 4
18 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast i32* [[P:%.*]] to i8*
19 ; CHECK-NEXT: [[SUNKADDR4:%.*]] = getelementptr i8, i8* [[TMP1]], i64 [[SUNKADDR3]]
20 ; CHECK-NEXT: [[TMP2:%.*]] = bitcast i8* [[SUNKADDR4]] to i32*
21 ; CHECK-NEXT: [[LOADED:%.*]] = load atomic i32, i32* [[TMP2]] unordered, align 4
22 ; CHECK-NEXT: [[COND_2:%.*]] = icmp eq i32 [[LOADED]], [[X:%.*]]
23 ; CHECK-NEXT: br i1 [[COND_2]], label [[FAILURE:%.*]], label [[LOOP]]
25 ; CHECK-NEXT: ret i32 -1
27 ; CHECK-NEXT: unreachable
32 loop: ; preds = %backedge, %entry
33 %iv = phi i64 [ %math, %backedge ], [ %len, %entry ]
34 %0 = call { i64, i1 } @llvm.uadd.with.overflow.i64(i64 %iv, i64 1)
35 %math = extractvalue { i64, i1 } %0, 0
36 %ov = extractvalue { i64, i1 } %0, 1
37 br i1 %ov, label %exit, label %backedge
39 backedge: ; preds = %loop
40 %sunkaddr = mul i64 %iv, 4
41 %1 = bitcast i32* %p to i8*
42 %sunkaddr1 = getelementptr i8, i8* %1, i64 %sunkaddr
43 %sunkaddr2 = getelementptr i8, i8* %sunkaddr1, i64 4
44 %2 = bitcast i8* %sunkaddr2 to i32*
45 %loaded = load atomic i32, i32* %2 unordered, align 4
46 %cond_2 = icmp eq i32 %loaded, %x
47 br i1 %cond_2, label %failure, label %loop
52 failure: ; preds = %backedge