brintos

brintos / llvm-project-archived public Read only

0
0
Text · 7.2 KiB · e9463b2 Raw
253 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt -S -passes=instcombine < %s | FileCheck %s3 4;5; Tests to show cases where computeKnownBits should be able to determine6; the known bits of a phi edge based off a conditional branch feeding the phi.7;8 9; %x either eq 7 or is set to 710define i64 @limit_i64_eq_7(i64 %x) {11; CHECK-LABEL: @limit_i64_eq_7(12; CHECK-NEXT:  entry:13; CHECK-NEXT:    [[CMP:%.*]] = icmp eq i64 [[X:%.*]], 714; CHECK-NEXT:    br i1 [[CMP]], label [[END:%.*]], label [[BODY:%.*]]15; CHECK:       body:16; CHECK-NEXT:    br label [[END]]17; CHECK:       end:18; CHECK-NEXT:    [[RES:%.*]] = phi i64 [ [[X]], [[ENTRY:%.*]] ], [ 7, [[BODY]] ]19; CHECK-NEXT:    ret i64 [[RES]]20;21entry:22  %cmp = icmp eq i64 %x, 723  br i1 %cmp, label %end, label %body24body:25  br label %end26end:27  %res = phi i64 [ %x, %entry ], [ 7, %body ]28  ret i64 %res29}30 31define i64 @limit_i64_eq_7_commuted(i64 %x) {32; CHECK-LABEL: @limit_i64_eq_7_commuted(33; CHECK-NEXT:  entry:34; CHECK-NEXT:    [[CMP:%.*]] = icmp eq i64 [[X:%.*]], 735; CHECK-NEXT:    br i1 [[CMP]], label [[END:%.*]], label [[BODY:%.*]]36; CHECK:       body:37; CHECK-NEXT:    br label [[BODY]]38; CHECK:       end:39; CHECK-NEXT:    [[RES:%.*]] = phi i64 [ [[X]], [[END]] ], [ 7, [[ENTRY:%.*]] ]40; CHECK-NEXT:    ret i64 [[RES]]41;42entry:43  %cmp = icmp eq i64 %x, 744  br i1 %cmp, label %body, label %end45body:46  br label %end47end:48  %res = phi i64 [ %x, %body ], [ 7, %entry ]49  ret i64 %res50}51 52define i64 @neg_limit_i64_eq_7(i64 %x) {53; CHECK-LABEL: @neg_limit_i64_eq_7(54; CHECK-NEXT:  entry:55; CHECK-NEXT:    [[CMP:%.*]] = icmp eq i64 [[X:%.*]], 756; CHECK-NEXT:    br i1 [[CMP]], label [[END:%.*]], label [[BODY:%.*]]57; CHECK:       body:58; CHECK-NEXT:    br label [[BODY]]59; CHECK:       end:60; CHECK-NEXT:    [[RES:%.*]] = phi i64 [ [[X]], [[ENTRY:%.*]] ], [ 7, [[END]] ]61; CHECK-NEXT:    ret i64 [[RES]]62;63entry:64  %cmp = icmp eq i64 %x, 765  br i1 %cmp, label %body, label %end66body:67  br label %end68end:69  %res = phi i64 [ %x, %entry ], [ 7, %body ]70  ret i64 %res71}72 73; %x either eq 255 or is set to 25574define i64 @limit_i64_ne_255(i64 %x) {75; CHECK-LABEL: @limit_i64_ne_255(76; CHECK-NEXT:  entry:77; CHECK-NEXT:    [[CMP:%.*]] = icmp ne i64 [[X:%.*]], 25578; CHECK-NEXT:    call void @use(i1 [[CMP]])79; CHECK-NEXT:    br i1 [[CMP]], label [[BODY:%.*]], label [[END:%.*]]80; CHECK:       body:81; CHECK-NEXT:    br label [[END]]82; CHECK:       end:83; CHECK-NEXT:    [[RES:%.*]] = phi i64 [ [[X]], [[ENTRY:%.*]] ], [ 255, [[BODY]] ]84; CHECK-NEXT:    ret i64 [[RES]]85;86entry:87  %cmp = icmp ne i64 %x, 25588  call void @use(i1 %cmp)89  br i1 %cmp, label %body, label %end90body:91  br label %end92end:93  %res = phi i64 [ %x, %entry ], [ 255, %body ]94  ret i64 %res95}96declare void @use(i1)97 98; %x either ule 15 or is masked with 1599define i64 @limit_i64_ule_15(i64 %x) {100; CHECK-LABEL: @limit_i64_ule_15(101; CHECK-NEXT:  entry:102; CHECK-NEXT:    [[CMP:%.*]] = icmp ult i64 [[X:%.*]], 16103; CHECK-NEXT:    br i1 [[CMP]], label [[END:%.*]], label [[BODY:%.*]]104; CHECK:       body:105; CHECK-NEXT:    [[MASK:%.*]] = and i64 [[X]], 15106; CHECK-NEXT:    br label [[END]]107; CHECK:       end:108; CHECK-NEXT:    [[X_MASK:%.*]] = phi i64 [ [[X]], [[ENTRY:%.*]] ], [ [[MASK]], [[BODY]] ]109; CHECK-NEXT:    ret i64 [[X_MASK]]110;111entry:112  %cmp = icmp ule i64 %x, 15113  br i1 %cmp, label %end, label %body114body:115  %mask = and i64 %x, 15116  br label %end117end:118  %x.mask = phi i64 [ %x, %entry ], [ %mask, %body ]119  %res = and i64 %x.mask, 15120  ret i64 %res121}122 123; %x either uge 8 or is masked with 7124define i64 @limit_i64_uge_8(i64 %x) {125; CHECK-LABEL: @limit_i64_uge_8(126; CHECK-NEXT:  entry:127; CHECK-NEXT:    [[CMP:%.*]] = icmp ugt i64 [[X:%.*]], 7128; CHECK-NEXT:    br i1 [[CMP]], label [[BODY:%.*]], label [[END:%.*]]129; CHECK:       body:130; CHECK-NEXT:    [[MASK:%.*]] = and i64 [[X]], 7131; CHECK-NEXT:    br label [[END]]132; CHECK:       end:133; CHECK-NEXT:    [[X_MASK:%.*]] = phi i64 [ [[X]], [[ENTRY:%.*]] ], [ [[MASK]], [[BODY]] ]134; CHECK-NEXT:    ret i64 [[X_MASK]]135;136entry:137  %cmp = icmp uge i64 %x, 8138  br i1 %cmp, label %body, label %end139body:140  %mask = and i64 %x, 7141  br label %end142end:143  %x.mask = phi i64 [ %x, %entry ], [ %mask, %body ]144  %res = and i64 %x.mask, 7145  ret i64 %res146}147 148; %x either ult 8 or is masked with 7149define i64 @limit_i64_ult_8(i64 %x) {150; CHECK-LABEL: @limit_i64_ult_8(151; CHECK-NEXT:  entry:152; CHECK-NEXT:    [[CMP:%.*]] = icmp ult i64 [[X:%.*]], 8153; CHECK-NEXT:    br i1 [[CMP]], label [[END:%.*]], label [[BODY:%.*]]154; CHECK:       body:155; CHECK-NEXT:    [[MASK:%.*]] = and i64 [[X]], 7156; CHECK-NEXT:    br label [[END]]157; CHECK:       end:158; CHECK-NEXT:    [[X_MASK:%.*]] = phi i64 [ [[X]], [[ENTRY:%.*]] ], [ [[MASK]], [[BODY]] ]159; CHECK-NEXT:    ret i64 [[X_MASK]]160;161entry:162  %cmp = icmp ult i64 %x, 8163  br i1 %cmp, label %end, label %body164body:165  %mask = and i64 %x, 7166  br label %end167end:168  %x.mask = phi i64 [ %x, %entry ], [ %mask, %body ]169  %res = and i64 %x.mask, 7170  ret i64 %res171}172 173; %x either ugt 7 or is masked with 7174define i64 @limit_i64_ugt_7(i64 %x) {175; CHECK-LABEL: @limit_i64_ugt_7(176; CHECK-NEXT:  entry:177; CHECK-NEXT:    [[CMP:%.*]] = icmp ugt i64 [[X:%.*]], 7178; CHECK-NEXT:    br i1 [[CMP]], label [[BODY:%.*]], label [[END:%.*]]179; CHECK:       body:180; CHECK-NEXT:    [[MASK:%.*]] = and i64 [[X]], 7181; CHECK-NEXT:    br label [[END]]182; CHECK:       end:183; CHECK-NEXT:    [[X_MASK:%.*]] = phi i64 [ [[X]], [[ENTRY:%.*]] ], [ [[MASK]], [[BODY]] ]184; CHECK-NEXT:    ret i64 [[X_MASK]]185;186entry:187  %cmp = icmp ugt i64 %x, 7188  br i1 %cmp, label %body, label %end189body:190  %mask = and i64 %x, 7191  br label %end192end:193  %x.mask = phi i64 [ %x, %entry ], [ %mask, %body ]194  %res = and i64 %x.mask, 7195  ret i64 %res196}197 198;199; negative tests200;201 202; %x either ule 15 or is masked with 15203define i64 @limit_i64_ule_15_mask3(i64 %x) {204; CHECK-LABEL: @limit_i64_ule_15_mask3(205; CHECK-NEXT:  entry:206; CHECK-NEXT:    [[CMP:%.*]] = icmp ult i64 [[X:%.*]], 16207; CHECK-NEXT:    br i1 [[CMP]], label [[END:%.*]], label [[BODY:%.*]]208; CHECK:       body:209; CHECK-NEXT:    [[MASK:%.*]] = and i64 [[X]], 15210; CHECK-NEXT:    br label [[END]]211; CHECK:       end:212; CHECK-NEXT:    [[X_MASK:%.*]] = phi i64 [ [[X]], [[ENTRY:%.*]] ], [ [[MASK]], [[BODY]] ]213; CHECK-NEXT:    [[RES:%.*]] = and i64 [[X_MASK]], 3214; CHECK-NEXT:    ret i64 [[RES]]215;216entry:217  %cmp = icmp ule i64 %x, 15218  br i1 %cmp, label %end, label %body219body:220  %mask = and i64 %x, 15221  br label %end222end:223  %x.mask = phi i64 [ %x, %entry ], [ %mask, %body ]224  %res = and i64 %x.mask, 3225  ret i64 %res226}227 228; %x either ult 8 or is masked with 7229define i64 @limit_i64_ult_8_mask1(i64 %x) {230; CHECK-LABEL: @limit_i64_ult_8_mask1(231; CHECK-NEXT:  entry:232; CHECK-NEXT:    [[CMP:%.*]] = icmp ult i64 [[X:%.*]], 8233; CHECK-NEXT:    br i1 [[CMP]], label [[END:%.*]], label [[BODY:%.*]]234; CHECK:       body:235; CHECK-NEXT:    [[MASK:%.*]] = and i64 [[X]], 7236; CHECK-NEXT:    br label [[END]]237; CHECK:       end:238; CHECK-NEXT:    [[X_MASK:%.*]] = phi i64 [ [[X]], [[ENTRY:%.*]] ], [ [[MASK]], [[BODY]] ]239; CHECK-NEXT:    [[RES:%.*]] = and i64 [[X_MASK]], 1240; CHECK-NEXT:    ret i64 [[RES]]241;242entry:243  %cmp = icmp ult i64 %x, 8244  br i1 %cmp, label %end, label %body245body:246  %mask = and i64 %x, 7247  br label %end248end:249  %x.mask = phi i64 [ %x, %entry ], [ %mask, %body ]250  %res = and i64 %x.mask, 1251  ret i64 %res252}253