brintos

brintos / llvm-project-archived public Read only

0
0
Text · 14.6 KiB · 2aebb73 Raw
356 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt -passes=loop-vectorize,dce,instcombine -force-vector-interleave=1 -force-vector-width=8 -S < %s | FileCheck %s3 4define i8 @reduction_and_trunc(ptr noalias nocapture %ptr) {5; CHECK-LABEL: @reduction_and_trunc(6; CHECK-NEXT:  entry:7; CHECK-NEXT:    br label [[VECTOR_PH:%.*]]8; CHECK:       vector.ph:9; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]10; CHECK:       vector.body:11; CHECK-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]12; CHECK-NEXT:    [[VEC_PHI:%.*]] = phi <8 x i8> [ <i8 0, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1>, [[VECTOR_PH]] ], [ [[TMP2:%.*]], [[VECTOR_BODY]] ]13; CHECK-NEXT:    [[TMP0:%.*]] = sext i32 [[INDEX]] to i6414; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i8, ptr [[PTR:%.*]], i64 [[TMP0]]15; CHECK-NEXT:    [[WIDE_LOAD:%.*]] = load <8 x i8>, ptr [[TMP1]], align 116; CHECK-NEXT:    [[TMP2]] = and <8 x i8> [[VEC_PHI]], [[WIDE_LOAD]]17; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 818; CHECK-NEXT:    [[TMP3:%.*]] = icmp eq i32 [[INDEX_NEXT]], 25619; CHECK-NEXT:    br i1 [[TMP3]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]20; CHECK:       middle.block:21; CHECK-NEXT:    br label [[FOR_BODY:%.*]]22; CHECK:       for.end:23; CHECK-NEXT:    [[AND_LCSSA_OFF0:%.*]] = call i8 @llvm.vector.reduce.and.v8i8(<8 x i8> [[TMP2]])24; CHECK-NEXT:    ret i8 [[AND_LCSSA_OFF0]]25;26entry:27  br label %for.body28 29for.body:30  %iv = phi i32 [ %iv.next, %for.body ], [ 0, %entry ]31  %sum.02p = phi i32 [ %and, %for.body ], [ 0, %entry ]32  %sum.02 = and i32 %sum.02p, 25533  %gep = getelementptr inbounds i8, ptr %ptr, i32 %iv34  %load = load i8, ptr %gep35  %ext = zext i8 %load to i3236  %and = and i32 %sum.02, %ext37  %iv.next = add i32 %iv, 138  %exitcond = icmp eq i32 %iv.next, 25639  br i1 %exitcond, label %for.end, label %for.body40 41for.end:42  %ret = trunc i32 %and to i843  ret i8 %ret44}45 46define i16 @reduction_or_trunc(ptr noalias nocapture %ptr) {47; CHECK-LABEL: @reduction_or_trunc(48; CHECK-NEXT:  entry:49; CHECK-NEXT:    br label [[VECTOR_PH:%.*]]50; CHECK:       vector.ph:51; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]52; CHECK:       vector.body:53; CHECK-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]54; CHECK-NEXT:    [[VEC_PHI:%.*]] = phi <8 x i16> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP2:%.*]], [[VECTOR_BODY]] ]55; CHECK-NEXT:    [[TMP0:%.*]] = sext i32 [[INDEX]] to i6456; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i16, ptr [[PTR:%.*]], i64 [[TMP0]]57; CHECK-NEXT:    [[WIDE_LOAD:%.*]] = load <8 x i16>, ptr [[TMP1]], align 258; CHECK-NEXT:    [[TMP2]] = or <8 x i16> [[VEC_PHI]], [[WIDE_LOAD]]59; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 860; CHECK-NEXT:    [[TMP3:%.*]] = icmp eq i32 [[INDEX_NEXT]], 25661; CHECK-NEXT:    br i1 [[TMP3]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP3:![0-9]+]]62; CHECK:       middle.block:63; CHECK-NEXT:    br label [[FOR_BODY:%.*]]64; CHECK:       for.end:65; CHECK-NEXT:    [[XOR_LCSSA_OFF0:%.*]] = call i16 @llvm.vector.reduce.or.v8i16(<8 x i16> [[TMP2]])66; CHECK-NEXT:    ret i16 [[XOR_LCSSA_OFF0]]67;68entry:69  br label %for.body70 71for.body:72  %iv = phi i32 [ %iv.next, %for.body ], [ 0, %entry ]73  %sum.02p = phi i32 [ %xor, %for.body ], [ 0, %entry ]74  %sum.02 = and i32 %sum.02p, 6553575  %gep = getelementptr inbounds i16, ptr %ptr, i32 %iv76  %load = load i16, ptr %gep77  %ext = zext i16 %load to i3278  %xor = or i32 %sum.02, %ext79  %iv.next = add i32 %iv, 180  %exitcond = icmp eq i32 %iv.next, 25681  br i1 %exitcond, label %for.end, label %for.body82 83for.end:84  %ret = trunc i32 %xor to i1685  ret i16 %ret86}87 88define i16 @reduction_xor_trunc(ptr noalias nocapture %ptr) {89; CHECK-LABEL: @reduction_xor_trunc(90; CHECK-NEXT:  entry:91; CHECK-NEXT:    br label [[VECTOR_PH:%.*]]92; CHECK:       vector.ph:93; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]94; CHECK:       vector.body:95; CHECK-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]96; CHECK-NEXT:    [[VEC_PHI:%.*]] = phi <8 x i16> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP2:%.*]], [[VECTOR_BODY]] ]97; CHECK-NEXT:    [[TMP0:%.*]] = sext i32 [[INDEX]] to i6498; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i16, ptr [[PTR:%.*]], i64 [[TMP0]]99; CHECK-NEXT:    [[WIDE_LOAD:%.*]] = load <8 x i16>, ptr [[TMP1]], align 2100; CHECK-NEXT:    [[TMP2]] = xor <8 x i16> [[VEC_PHI]], [[WIDE_LOAD]]101; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 8102; CHECK-NEXT:    [[TMP3:%.*]] = icmp eq i32 [[INDEX_NEXT]], 256103; CHECK-NEXT:    br i1 [[TMP3]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP4:![0-9]+]]104; CHECK:       middle.block:105; CHECK-NEXT:    br label [[FOR_BODY:%.*]]106; CHECK:       for.end:107; CHECK-NEXT:    [[XOR_LCSSA_OFF0:%.*]] = call i16 @llvm.vector.reduce.xor.v8i16(<8 x i16> [[TMP2]])108; CHECK-NEXT:    ret i16 [[XOR_LCSSA_OFF0]]109;110entry:111  br label %for.body112 113for.body:114  %iv = phi i32 [ %iv.next, %for.body ], [ 0, %entry ]115  %sum.02p = phi i32 [ %xor, %for.body ], [ 0, %entry ]116  %sum.02 = and i32 %sum.02p, 65535117  %gep = getelementptr inbounds i16, ptr %ptr, i32 %iv118  %load = load i16, ptr %gep119  %ext = zext i16 %load to i32120  %xor = xor i32 %sum.02, %ext121  %iv.next = add i32 %iv, 1122  %exitcond = icmp eq i32 %iv.next, 256123  br i1 %exitcond, label %for.end, label %for.body124 125for.end:126  %ret = trunc i32 %xor to i16127  ret i16 %ret128}129 130define i8 @reduction_smin_trunc(ptr noalias nocapture %ptr) {131; CHECK-LABEL: @reduction_smin_trunc(132; CHECK-NEXT:  entry:133; CHECK-NEXT:    br label [[FOR_BODY:%.*]]134; CHECK:       for.body:135; CHECK-NEXT:    [[IV:%.*]] = phi i32 [ [[IV_NEXT:%.*]], [[FOR_BODY]] ], [ 0, [[ENTRY:%.*]] ]136; CHECK-NEXT:    [[SUM_02P:%.*]] = phi i32 [ [[MIN:%.*]], [[FOR_BODY]] ], [ 256, [[ENTRY]] ]137; CHECK-NEXT:    [[SUM_02:%.*]] = and i32 [[SUM_02P]], 255138; CHECK-NEXT:    [[TMP0:%.*]] = sext i32 [[IV]] to i64139; CHECK-NEXT:    [[GEP:%.*]] = getelementptr inbounds i8, ptr [[PTR:%.*]], i64 [[TMP0]]140; CHECK-NEXT:    [[LOAD:%.*]] = load i8, ptr [[GEP]], align 1141; CHECK-NEXT:    [[EXT:%.*]] = sext i8 [[LOAD]] to i32142; CHECK-NEXT:    [[MIN]] = call i32 @llvm.smin.i32(i32 [[SUM_02]], i32 [[EXT]])143; CHECK-NEXT:    [[IV_NEXT]] = add i32 [[IV]], 1144; CHECK-NEXT:    [[EXITCOND:%.*]] = icmp eq i32 [[IV_NEXT]], 256145; CHECK-NEXT:    br i1 [[EXITCOND]], label [[FOR_END:%.*]], label [[FOR_BODY]]146; CHECK:       for.end:147; CHECK-NEXT:    [[RET:%.*]] = trunc i32 [[MIN]] to i8148; CHECK-NEXT:    ret i8 [[RET]]149;150entry:151  br label %for.body152 153for.body:154  %iv = phi i32 [ %iv.next, %for.body ], [ 0, %entry ]155  %sum.02p = phi i32 [ %min, %for.body ], [ 256, %entry ]156  %sum.02 = and i32 %sum.02p, 255157  %gep = getelementptr inbounds i8, ptr %ptr, i32 %iv158  %load = load i8, ptr %gep159  %ext = sext i8 %load to i32160  %icmp = icmp slt i32 %sum.02, %ext161  %min = select i1 %icmp, i32 %sum.02, i32 %ext162  %iv.next = add i32 %iv, 1163  %exitcond = icmp eq i32 %iv.next, 256164  br i1 %exitcond, label %for.end, label %for.body165 166for.end:167  %ret = trunc i32 %min to i8168  ret i8 %ret169}170 171define i8 @reduction_umin_trunc(ptr noalias nocapture %ptr) {172; CHECK-LABEL: @reduction_umin_trunc(173; CHECK-NEXT:  entry:174; CHECK-NEXT:    br label [[FOR_BODY:%.*]]175; CHECK:       for.body:176; CHECK-NEXT:    [[IV:%.*]] = phi i32 [ [[IV_NEXT:%.*]], [[FOR_BODY]] ], [ 0, [[ENTRY:%.*]] ]177; CHECK-NEXT:    [[SUM_02P:%.*]] = phi i32 [ [[MIN:%.*]], [[FOR_BODY]] ], [ 0, [[ENTRY]] ]178; CHECK-NEXT:    [[SUM_02:%.*]] = and i32 [[SUM_02P]], 255179; CHECK-NEXT:    [[TMP0:%.*]] = sext i32 [[IV]] to i64180; CHECK-NEXT:    [[GEP:%.*]] = getelementptr inbounds i8, ptr [[PTR:%.*]], i64 [[TMP0]]181; CHECK-NEXT:    [[LOAD:%.*]] = load i8, ptr [[GEP]], align 1182; CHECK-NEXT:    [[EXT:%.*]] = zext i8 [[LOAD]] to i32183; CHECK-NEXT:    [[MIN]] = call i32 @llvm.umin.i32(i32 [[SUM_02]], i32 [[EXT]])184; CHECK-NEXT:    [[IV_NEXT]] = add i32 [[IV]], 1185; CHECK-NEXT:    [[EXITCOND:%.*]] = icmp eq i32 [[IV_NEXT]], 256186; CHECK-NEXT:    br i1 [[EXITCOND]], label [[FOR_END:%.*]], label [[FOR_BODY]]187; CHECK:       for.end:188; CHECK-NEXT:    [[RET:%.*]] = trunc nuw i32 [[MIN]] to i8189; CHECK-NEXT:    ret i8 [[RET]]190;191entry:192  br label %for.body193 194for.body:195  %iv = phi i32 [ %iv.next, %for.body ], [ 0, %entry ]196  %sum.02p = phi i32 [ %min, %for.body ], [ 0, %entry ]197  %sum.02 = and i32 %sum.02p, 255198  %gep = getelementptr inbounds i8, ptr %ptr, i32 %iv199  %load = load i8, ptr %gep200  %ext = zext i8 %load to i32201  %icmp = icmp ult i32 %sum.02, %ext202  %min = select i1 %icmp, i32 %sum.02, i32 %ext203  %iv.next = add i32 %iv, 1204  %exitcond = icmp eq i32 %iv.next, 256205  br i1 %exitcond, label %for.end, label %for.body206 207for.end:208  %ret = trunc i32 %min to i8209  ret i8 %ret210}211 212define i16 @reduction_smax_trunc(ptr noalias nocapture %ptr) {213; CHECK-LABEL: @reduction_smax_trunc(214; CHECK-NEXT:  entry:215; CHECK-NEXT:    br label [[FOR_BODY:%.*]]216; CHECK:       for.body:217; CHECK-NEXT:    [[IV:%.*]] = phi i32 [ [[IV_NEXT:%.*]], [[FOR_BODY]] ], [ 0, [[ENTRY:%.*]] ]218; CHECK-NEXT:    [[SUM_02P:%.*]] = phi i32 [ [[MIN:%.*]], [[FOR_BODY]] ], [ 0, [[ENTRY]] ]219; CHECK-NEXT:    [[SUM_02:%.*]] = and i32 [[SUM_02P]], 65535220; CHECK-NEXT:    [[TMP0:%.*]] = sext i32 [[IV]] to i64221; CHECK-NEXT:    [[GEP:%.*]] = getelementptr inbounds i16, ptr [[PTR:%.*]], i64 [[TMP0]]222; CHECK-NEXT:    [[LOAD:%.*]] = load i16, ptr [[GEP]], align 2223; CHECK-NEXT:    [[EXT:%.*]] = sext i16 [[LOAD]] to i32224; CHECK-NEXT:    [[MIN]] = call i32 @llvm.smax.i32(i32 [[SUM_02]], i32 [[EXT]])225; CHECK-NEXT:    [[IV_NEXT]] = add i32 [[IV]], 1226; CHECK-NEXT:    [[EXITCOND:%.*]] = icmp eq i32 [[IV_NEXT]], 256227; CHECK-NEXT:    br i1 [[EXITCOND]], label [[FOR_END:%.*]], label [[FOR_BODY]]228; CHECK:       for.end:229; CHECK-NEXT:    [[RET:%.*]] = trunc i32 [[MIN]] to i16230; CHECK-NEXT:    ret i16 [[RET]]231;232entry:233  br label %for.body234 235for.body:236  %iv = phi i32 [ %iv.next, %for.body ], [ 0, %entry ]237  %sum.02p = phi i32 [ %min, %for.body ], [ 0, %entry ]238  %sum.02 = and i32 %sum.02p, 65535239  %gep = getelementptr inbounds i16, ptr %ptr, i32 %iv240  %load = load i16, ptr %gep241  %ext = sext i16 %load to i32242  %icmp = icmp sgt i32 %sum.02, %ext243  %min = select i1 %icmp, i32 %sum.02, i32 %ext244  %iv.next = add i32 %iv, 1245  %exitcond = icmp eq i32 %iv.next, 256246  br i1 %exitcond, label %for.end, label %for.body247 248for.end:249  %ret = trunc i32 %min to i16250  ret i16 %ret251}252 253define i16 @reduction_umax_trunc(ptr noalias nocapture %ptr) {254; CHECK-LABEL: @reduction_umax_trunc(255; CHECK-NEXT:  entry:256; CHECK-NEXT:    br label [[FOR_BODY:%.*]]257; CHECK:       for.body:258; CHECK-NEXT:    [[IV:%.*]] = phi i32 [ [[IV_NEXT:%.*]], [[FOR_BODY]] ], [ 0, [[ENTRY:%.*]] ]259; CHECK-NEXT:    [[SUM_02P:%.*]] = phi i32 [ [[MIN:%.*]], [[FOR_BODY]] ], [ 0, [[ENTRY]] ]260; CHECK-NEXT:    [[SUM_02:%.*]] = and i32 [[SUM_02P]], 65535261; CHECK-NEXT:    [[TMP0:%.*]] = sext i32 [[IV]] to i64262; CHECK-NEXT:    [[GEP:%.*]] = getelementptr inbounds i16, ptr [[PTR:%.*]], i64 [[TMP0]]263; CHECK-NEXT:    [[LOAD:%.*]] = load i16, ptr [[GEP]], align 2264; CHECK-NEXT:    [[EXT:%.*]] = zext i16 [[LOAD]] to i32265; CHECK-NEXT:    [[MIN]] = call i32 @llvm.umax.i32(i32 [[SUM_02]], i32 [[EXT]])266; CHECK-NEXT:    [[IV_NEXT]] = add i32 [[IV]], 1267; CHECK-NEXT:    [[EXITCOND:%.*]] = icmp eq i32 [[IV_NEXT]], 256268; CHECK-NEXT:    br i1 [[EXITCOND]], label [[FOR_END:%.*]], label [[FOR_BODY]]269; CHECK:       for.end:270; CHECK-NEXT:    [[RET:%.*]] = trunc nuw i32 [[MIN]] to i16271; CHECK-NEXT:    ret i16 [[RET]]272;273entry:274  br label %for.body275 276for.body:277  %iv = phi i32 [ %iv.next, %for.body ], [ 0, %entry ]278  %sum.02p = phi i32 [ %min, %for.body ], [ 0, %entry ]279  %sum.02 = and i32 %sum.02p, 65535280  %gep = getelementptr inbounds i16, ptr %ptr, i32 %iv281  %load = load i16, ptr %gep282  %ext = zext i16 %load to i32283  %icmp = icmp ugt i32 %sum.02, %ext284  %min = select i1 %icmp, i32 %sum.02, i32 %ext285  %iv.next = add i32 %iv, 1286  %exitcond = icmp eq i32 %iv.next, 256287  br i1 %exitcond, label %for.end, label %for.body288 289for.end:290  %ret = trunc i32 %min to i16291  ret i16 %ret292}293 294; Test case for https://github.com/llvm/llvm-project/issues/81415.295define i32 @reduction_and_or(i16 %a, i32 %b, ptr %src) {296; CHECK-LABEL: @reduction_and_or(297; CHECK-NEXT:  entry:298; CHECK-NEXT:    br label [[VECTOR_PH:%.*]]299; CHECK:       vector.ph:300; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]301; CHECK:       vector.body:302; CHECK-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]303; CHECK-NEXT:    [[VEC_PHI:%.*]] = phi <8 x i32> [ <i32 10, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0>, [[VECTOR_PH]] ], [ [[TMP2:%.*]], [[VECTOR_BODY]] ]304; CHECK-NEXT:    [[TMP0:%.*]] = sext i32 [[INDEX]] to i64305; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds i32, ptr [[SRC:%.*]], i64 [[TMP0]]306; CHECK-NEXT:    [[WIDE_LOAD:%.*]] = load <8 x i32>, ptr [[TMP1]], align 4307; CHECK-NEXT:    [[TMP2]] = or <8 x i32> [[VEC_PHI]], [[WIDE_LOAD]]308; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 8309; CHECK-NEXT:    [[TMP3:%.*]] = icmp eq i32 [[INDEX_NEXT]], 992310; CHECK-NEXT:    br i1 [[TMP3]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP5:![0-9]+]]311; CHECK:       middle.block:312; CHECK-NEXT:    br label [[SCALAR_PH:%.*]]313; CHECK:       scalar.ph:314; CHECK-NEXT:    [[BC_MERGE_RDX:%.*]] = call i32 @llvm.vector.reduce.or.v8i32(<8 x i32> [[TMP2]])315; CHECK-NEXT:    br label [[LOOP:%.*]]316; CHECK:       loop:317; CHECK-NEXT:    [[IV:%.*]] = phi i32 [ 992, [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]318; CHECK-NEXT:    [[OR67:%.*]] = phi i32 [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ], [ [[OR:%.*]], [[LOOP]] ]319; CHECK-NEXT:    [[TMP5:%.*]] = zext nneg i32 [[IV]] to i64320; CHECK-NEXT:    [[GEP:%.*]] = getelementptr inbounds nuw i32, ptr [[SRC]], i64 [[TMP5]]321; CHECK-NEXT:    [[L:%.*]] = load i32, ptr [[GEP]], align 4322; CHECK-NEXT:    [[OR]] = or i32 [[OR67]], [[L]]323; CHECK-NEXT:    [[IV_NEXT]] = add nuw nsw i32 [[IV]], 1324; CHECK-NEXT:    [[TOBOOL_NOT:%.*]] = icmp eq i32 [[IV_NEXT]], 999325; CHECK-NEXT:    br i1 [[TOBOOL_NOT]], label [[EXIT:%.*]], label [[LOOP]], !llvm.loop [[LOOP6:![0-9]+]]326; CHECK:       exit:327; CHECK-NEXT:    ret i32 [[OR]]328;329entry:330  %ext1 = zext i16 %a to i32331  br label %loop332 333loop:334  %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]335  %or67 = phi i32 [ 10, %entry ], [ %or, %loop ]336  %t = trunc i32 %b to i16337  %ext = sext i16 %t to i32338  %cmp = icmp sgt i32 %ext, %ext1339  %ext2 = zext i1 %cmp to i32340  %cmp3 = icmp sge i32 %iv, %ext2341  %ext4 = zext i1 %cmp3 to i32342  %div = sdiv i32 %ext4, %b343  %and = and i32 %div, 0344  %gep = getelementptr inbounds i32, ptr %src, i32 %iv345  %l = load i32, ptr %gep346  %add = add i32 %and, %l347  %or = or i32 %or67, %add348  %iv.next = add nsw i32 %iv, 1349  %tobool.not = icmp eq i32 %iv.next, 999350  br i1 %tobool.not, label %exit, label %loop351 352exit:353  %or.lcssa = phi i32 [ %or, %loop ]354  ret i32 %or.lcssa355}356