1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt < %s -instcombine -S | FileCheck %s 3target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" 4target triple = "x86_64-unknown-linux-gnu" 5 6define i32 @foo(i8* nocapture readnone %match, i32 %cur_match, i32 %best_len, i32 %scan_end, i32* nocapture readonly %prev, i32 %limit, i32 %chain_length, i8* nocapture readonly %win, i32 %wmask) { 7; CHECK-LABEL: @foo( 8; CHECK-NEXT: entry: 9; CHECK-NEXT: [[IDX_EXT2:%.*]] = zext i32 [[CUR_MATCH:%.*]] to i64 10; CHECK-NEXT: [[ADD_PTR4:%.*]] = getelementptr inbounds i8, i8* [[WIN:%.*]], i64 [[IDX_EXT2]] 11; CHECK-NEXT: [[IDX_EXT1:%.*]] = zext i32 [[BEST_LEN:%.*]] to i64 12; CHECK-NEXT: [[ADD_PTR25:%.*]] = getelementptr inbounds i8, i8* [[ADD_PTR4]], i64 [[IDX_EXT1]] 13; CHECK-NEXT: [[ADD_PTR36:%.*]] = getelementptr inbounds i8, i8* [[ADD_PTR25]], i64 -1 14; CHECK-NEXT: [[TMP0:%.*]] = bitcast i8* [[ADD_PTR36]] to i32* 15; CHECK-NEXT: [[TMP1:%.*]] = load i32, i32* [[TMP0]], align 4 16; CHECK-NEXT: [[CMP7:%.*]] = icmp eq i32 [[TMP1]], [[SCAN_END:%.*]] 17; CHECK-NEXT: br i1 [[CMP7]], label [[DO_END:%.*]], label [[IF_THEN_LR_PH:%.*]] 18; CHECK: if.then.lr.ph: 19; CHECK-NEXT: br label [[IF_THEN:%.*]] 20; CHECK: do.body: 21; CHECK-NEXT: [[IDX_EXT:%.*]] = zext i32 [[TMP4:%.*]] to i64 22; CHECK-NEXT: [[ADD_PTR:%.*]] = getelementptr inbounds i8, i8* [[WIN]], i64 [[IDX_EXT1]] 23; CHECK-NEXT: [[ADD_PTR2:%.*]] = getelementptr inbounds i8, i8* [[ADD_PTR]], i64 -1 24; CHECK-NEXT: [[ADD_PTR3:%.*]] = getelementptr inbounds i8, i8* [[ADD_PTR2]], i64 [[IDX_EXT]] 25; CHECK-NEXT: [[TMP2:%.*]] = bitcast i8* [[ADD_PTR3]] to i32* 26; CHECK-NEXT: [[TMP3:%.*]] = load i32, i32* [[TMP2]], align 4 27; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[TMP3]], [[SCAN_END]] 28; CHECK-NEXT: br i1 [[CMP]], label [[DO_END]], label [[IF_THEN]] 29; CHECK: if.then: 30; CHECK-NEXT: [[CUR_MATCH_ADDR_09:%.*]] = phi i32 [ [[CUR_MATCH]], [[IF_THEN_LR_PH]] ], [ [[TMP4]], [[DO_BODY:%.*]] ] 31; CHECK-NEXT: [[CHAIN_LENGTH_ADDR_08:%.*]] = phi i32 [ [[CHAIN_LENGTH:%.*]], [[IF_THEN_LR_PH]] ], [ [[DEC:%.*]], [[DO_BODY]] ] 32; CHECK-NEXT: [[AND:%.*]] = and i32 [[CUR_MATCH_ADDR_09]], [[WMASK:%.*]] 33; CHECK-NEXT: [[IDXPROM:%.*]] = zext i32 [[AND]] to i64 34; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, i32* [[PREV:%.*]], i64 [[IDXPROM]] 35; CHECK-NEXT: [[TMP4]] = load i32, i32* [[ARRAYIDX]], align 4 36; CHECK-NEXT: [[CMP4:%.*]] = icmp ugt i32 [[TMP4]], [[LIMIT:%.*]] 37; CHECK-NEXT: br i1 [[CMP4]], label [[LAND_LHS_TRUE:%.*]], label [[DO_END]] 38; CHECK: land.lhs.true: 39; CHECK-NEXT: [[DEC]] = add i32 [[CHAIN_LENGTH_ADDR_08]], -1 40; CHECK-NEXT: [[CMP5:%.*]] = icmp eq i32 [[DEC]], 0 41; CHECK-NEXT: br i1 [[CMP5]], label [[DO_END]], label [[DO_BODY]] 42; CHECK: do.end: 43; CHECK-NEXT: [[CONT_0:%.*]] = phi i32 [ 1, [[ENTRY:%.*]] ], [ 0, [[IF_THEN]] ], [ 0, [[LAND_LHS_TRUE]] ], [ 1, [[DO_BODY]] ] 44; CHECK-NEXT: ret i32 [[CONT_0]] 45; 46entry: 47 %idx.ext2 = zext i32 %cur_match to i64 48 %add.ptr4 = getelementptr inbounds i8, i8* %win, i64 %idx.ext2 49 %idx.ext1 = zext i32 %best_len to i64 50 %add.ptr25 = getelementptr inbounds i8, i8* %add.ptr4, i64 %idx.ext1 51 %add.ptr36 = getelementptr inbounds i8, i8* %add.ptr25, i64 -1 52 %0 = bitcast i8* %add.ptr36 to i32* 53 %1 = load i32, i32* %0, align 4 54 %cmp7 = icmp eq i32 %1, %scan_end 55 br i1 %cmp7, label %do.end, label %if.then.lr.ph 56 57if.then.lr.ph: ; preds = %entry 58 br label %if.then 59 60do.body: ; preds = %land.lhs.true 61 %chain_length.addr.0 = phi i32 [ %dec, %land.lhs.true ] 62 %cur_match.addr.0 = phi i32 [ %4, %land.lhs.true ] 63 %idx.ext = zext i32 %cur_match.addr.0 to i64 64 %add.ptr = getelementptr inbounds i8, i8* %win, i64 %idx.ext 65 %add.ptr2 = getelementptr inbounds i8, i8* %add.ptr, i64 %idx.ext1 66 %add.ptr3 = getelementptr inbounds i8, i8* %add.ptr2, i64 -1 67 %2 = bitcast i8* %add.ptr3 to i32* 68 %3 = load i32, i32* %2, align 4 69 %cmp = icmp eq i32 %3, %scan_end 70 br i1 %cmp, label %do.end, label %if.then 71 72if.then: ; preds = %if.then.lr.ph, %do.body 73 %cur_match.addr.09 = phi i32 [ %cur_match, %if.then.lr.ph ], [ %cur_match.addr.0, %do.body ] 74 %chain_length.addr.08 = phi i32 [ %chain_length, %if.then.lr.ph ], [ %chain_length.addr.0, %do.body ] 75 %and = and i32 %cur_match.addr.09, %wmask 76 %idxprom = zext i32 %and to i64 77 %arrayidx = getelementptr inbounds i32, i32* %prev, i64 %idxprom 78 %4 = load i32, i32* %arrayidx, align 4 79 %cmp4 = icmp ugt i32 %4, %limit 80 br i1 %cmp4, label %land.lhs.true, label %do.end 81 82land.lhs.true: ; preds = %if.then 83 %dec = add i32 %chain_length.addr.08, -1 84 %cmp5 = icmp eq i32 %dec, 0 85 br i1 %cmp5, label %do.end, label %do.body 86 87do.end: ; preds = %do.body, %land.lhs.true, %if.then, %entry 88 %cont.0 = phi i32 [ 1, %entry ], [ 0, %if.then ], [ 0, %land.lhs.true ], [ 1, %do.body ] 89 ret i32 %cont.0 90} 91 92declare void @blackhole(<2 x i8*>) 93 94define void @PR37005(i8* %base, i8** %in) { 95; CHECK-LABEL: @PR37005( 96; CHECK-NEXT: entry: 97; CHECK-NEXT: br label [[LOOP:%.*]] 98; CHECK: loop: 99; CHECK-NEXT: [[E2:%.*]] = getelementptr inbounds i8*, i8** [[IN:%.*]], i64 undef 100; CHECK-NEXT: [[E4:%.*]] = getelementptr inbounds i8*, i8** [[E2]], <2 x i64> <i64 0, i64 1> 101; CHECK-NEXT: [[PI1:%.*]] = ptrtoint <2 x i8**> [[E4]] to <2 x i64> 102; CHECK-NEXT: [[LR1:%.*]] = lshr <2 x i64> [[PI1]], <i64 21, i64 21> 103; CHECK-NEXT: [[SL1:%.*]] = shl nuw nsw <2 x i64> [[LR1]], <i64 7, i64 7> 104; CHECK-NEXT: [[E51:%.*]] = getelementptr inbounds i8, i8* [[BASE:%.*]], i64 80 105; CHECK-NEXT: [[E6:%.*]] = getelementptr inbounds i8, i8* [[E51]], <2 x i64> [[SL1]] 106; CHECK-NEXT: call void @blackhole(<2 x i8*> [[E6]]) 107; CHECK-NEXT: br label [[LOOP]] 108; 109entry: 110 br label %loop 111 112loop: 113 %e1 = getelementptr inbounds i8*, i8** %in, i64 undef 114 %e2 = getelementptr inbounds i8*, i8** %e1, i64 6 115 %bc1 = bitcast i8** %e2 to <2 x i8*>* 116 %e3 = getelementptr inbounds <2 x i8*>, <2 x i8*>* %bc1, i64 0, i64 0 117 %e4 = getelementptr inbounds i8*, i8** %e3, <2 x i64> <i64 0, i64 1> 118 %pi1 = ptrtoint <2 x i8**> %e4 to <2 x i64> 119 %lr1 = lshr <2 x i64> %pi1, <i64 21, i64 21> 120 %sl1 = shl nuw nsw <2 x i64> %lr1, <i64 7, i64 7> 121 %e5 = getelementptr inbounds i8, i8* %base, <2 x i64> %sl1 122 %e6 = getelementptr inbounds i8, <2 x i8*> %e5, i64 80 123 call void @blackhole(<2 x i8*> %e6) 124 br label %loop 125} 126 127define void @PR37005_2(i8* %base, i8** %in) { 128; CHECK-LABEL: @PR37005_2( 129; CHECK-NEXT: entry: 130; CHECK-NEXT: br label [[LOOP:%.*]] 131; CHECK: loop: 132; CHECK-NEXT: [[E2:%.*]] = getelementptr inbounds i8*, i8** [[IN:%.*]], i64 undef 133; CHECK-NEXT: [[PI1:%.*]] = ptrtoint i8** [[E2]] to i64 134; CHECK-NEXT: [[LR1:%.*]] = lshr i64 [[PI1]], 21 135; CHECK-NEXT: [[SL1:%.*]] = shl nuw nsw i64 [[LR1]], 7 136; CHECK-NEXT: [[E51:%.*]] = getelementptr inbounds i8, i8* [[BASE:%.*]], <2 x i64> <i64 80, i64 60> 137; CHECK-NEXT: [[E6:%.*]] = getelementptr inbounds i8, <2 x i8*> [[E51]], i64 [[SL1]] 138; CHECK-NEXT: call void @blackhole(<2 x i8*> [[E6]]) 139; CHECK-NEXT: br label [[LOOP]] 140; 141entry: 142 br label %loop 143 144loop: 145 %e1 = getelementptr inbounds i8*, i8** %in, i64 undef 146 %e2 = getelementptr inbounds i8*, i8** %e1, i64 6 147 %pi1 = ptrtoint i8** %e2 to i64 148 %lr1 = lshr i64 %pi1, 21 149 %sl1 = shl nuw nsw i64 %lr1, 7 150 %e5 = getelementptr inbounds i8, i8* %base, i64 %sl1 151 %e6 = getelementptr inbounds i8, i8* %e5, <2 x i64> <i64 80, i64 60> 152 call void @blackhole(<2 x i8*> %e6) 153 br label %loop 154} 155 156define void @PR37005_3(<2 x i8*> %base, i8** %in) { 157; CHECK-LABEL: @PR37005_3( 158; CHECK-NEXT: entry: 159; CHECK-NEXT: br label [[LOOP:%.*]] 160; CHECK: loop: 161; CHECK-NEXT: [[E2:%.*]] = getelementptr inbounds i8*, i8** [[IN:%.*]], i64 undef 162; CHECK-NEXT: [[E4:%.*]] = getelementptr inbounds i8*, i8** [[E2]], <2 x i64> <i64 0, i64 1> 163; CHECK-NEXT: [[PI1:%.*]] = ptrtoint <2 x i8**> [[E4]] to <2 x i64> 164; CHECK-NEXT: [[LR1:%.*]] = lshr <2 x i64> [[PI1]], <i64 21, i64 21> 165; CHECK-NEXT: [[SL1:%.*]] = shl nuw nsw <2 x i64> [[LR1]], <i64 7, i64 7> 166; CHECK-NEXT: [[E5:%.*]] = getelementptr inbounds i8, <2 x i8*> [[BASE:%.*]], i64 80 167; CHECK-NEXT: [[E6:%.*]] = getelementptr inbounds i8, <2 x i8*> [[E5]], <2 x i64> [[SL1]] 168; CHECK-NEXT: call void @blackhole(<2 x i8*> [[E6]]) 169; CHECK-NEXT: br label [[LOOP]] 170; 171entry: 172 br label %loop 173 174loop: 175 %e1 = getelementptr inbounds i8*, i8** %in, i64 undef 176 %e2 = getelementptr inbounds i8*, i8** %e1, i64 6 177 %bc1 = bitcast i8** %e2 to <2 x i8*>* 178 %e3 = getelementptr inbounds <2 x i8*>, <2 x i8*>* %bc1, i64 0, i64 0 179 %e4 = getelementptr inbounds i8*, i8** %e3, <2 x i64> <i64 0, i64 1> 180 %pi1 = ptrtoint <2 x i8**> %e4 to <2 x i64> 181 %lr1 = lshr <2 x i64> %pi1, <i64 21, i64 21> 182 %sl1 = shl nuw nsw <2 x i64> %lr1, <i64 7, i64 7> 183 %e5 = getelementptr inbounds i8, <2 x i8*> %base, <2 x i64> %sl1 184 %e6 = getelementptr inbounds i8, <2 x i8*> %e5, i64 80 185 call void @blackhole(<2 x i8*> %e6) 186 br label %loop 187} 188