1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -sink-common-insts -S < %s | FileCheck %s
4 ; Test that we tail merge this kind of code with glibc-style assertion
7 ; void merge_glibc_asserts(unsigned x, unsigned y) {
13 ; glibc's __assert_fail function takes four parameters, and it is profitable to
16 @.str = private unnamed_addr constant [6 x i8] c"x < y\00", align 1
17 @.str.1 = private unnamed_addr constant [6 x i8] c"t.cpp\00", align 1
18 @__PRETTY_FUNCTION__._Z1fjj = private unnamed_addr constant [35 x i8] c"void f(unsigned int, unsigned int)\00", align 1
19 @.str.2 = private unnamed_addr constant [10 x i8] c"y - x > 7\00", align 1
20 @.str.3 = private unnamed_addr constant [11 x i8] c"y - x < 40\00", align 1
22 declare void @glibc_assert_fail(ptr, ptr, i32, ptr)
24 define void @merge_glibc_asserts(i32 %x, i32 %y) {
25 ; CHECK-LABEL: @merge_glibc_asserts(
27 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32 [[Y:%.*]], [[X:%.*]]
28 ; CHECK-NEXT: br i1 [[CMP]], label [[COND_END:%.*]], label [[COND_FALSE:%.*]]
30 ; CHECK-NEXT: tail call void @glibc_assert_fail(ptr @.str, ptr @.str.1, i32 3, ptr @__PRETTY_FUNCTION__._Z1fjj)
31 ; CHECK-NEXT: unreachable
33 ; CHECK-NEXT: [[SUB:%.*]] = sub i32 [[Y]], [[X]]
34 ; CHECK-NEXT: [[CMP1:%.*]] = icmp ugt i32 [[SUB]], 7
35 ; CHECK-NEXT: br i1 [[CMP1]], label [[COND_END4:%.*]], label [[COND_FALSE3:%.*]]
37 ; CHECK-NEXT: tail call void @glibc_assert_fail(ptr @.str.2, ptr @.str.1, i32 4, ptr @__PRETTY_FUNCTION__._Z1fjj)
38 ; CHECK-NEXT: unreachable
40 ; CHECK-NEXT: [[CMP6:%.*]] = icmp ult i32 [[SUB]], 40
41 ; CHECK-NEXT: br i1 [[CMP6]], label [[COND_END9:%.*]], label [[COND_FALSE8:%.*]]
43 ; CHECK-NEXT: tail call void @glibc_assert_fail(ptr @.str.3, ptr @.str.1, i32 5, ptr @__PRETTY_FUNCTION__._Z1fjj)
44 ; CHECK-NEXT: unreachable
46 ; CHECK-NEXT: ret void
49 %cmp = icmp ugt i32 %y, %x
50 br i1 %cmp, label %cond.end, label %cond.false
52 cond.false: ; preds = %entry
53 tail call void @glibc_assert_fail(ptr @.str, ptr @.str.1, i32 3, ptr @__PRETTY_FUNCTION__._Z1fjj) #2
56 cond.end: ; preds = %entry
58 %cmp1 = icmp ugt i32 %sub, 7
59 br i1 %cmp1, label %cond.end4, label %cond.false3
61 cond.false3: ; preds = %cond.end
62 tail call void @glibc_assert_fail(ptr @.str.2, ptr @.str.1, i32 4, ptr @__PRETTY_FUNCTION__._Z1fjj) #2
65 cond.end4: ; preds = %cond.end
66 %cmp6 = icmp ult i32 %sub, 40
67 br i1 %cmp6, label %cond.end9, label %cond.false8
69 cond.false8: ; preds = %cond.end4
70 tail call void @glibc_assert_fail(ptr @.str.3, ptr @.str.1, i32 5, ptr @__PRETTY_FUNCTION__._Z1fjj) #2
73 cond.end9: ; preds = %cond.end4