166 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt < %s -passes=loop-vectorize -force-vector-width=4 -S | FileCheck %s3 4 5; Test cases below are reduced (and slightly modified) reproducers based on a6; problem seen when compiling a C program like this:7;8; #include <stdint.h>9; #include <stdio.h>10;11; int y = 0;12; int b = 1;13; int d = 1;14;15; int main() {16; #pragma clang loop vectorize_width(4)17; for (int i = 0; i < 3; ++i) {18; b = (y == 0) ? d : (d / y);19; }20;21; if (b == 1)22; printf("GOOD!\n");23; else24; printf("BAD!\n");25; }26;27; When compiled+executed using28; build-all/bin/clang -O1 lv-bug.c && ./a.out29; the result is "GOOD!"30;31; When compiled+executed using32; build-all/bin/clang -O1 lv-bug.c -fvectorize && ./a.out33; the result is "BAD!"34 35 36; This test case miscompiled with clang 8.0.0 (see PR43166), now we get37; loop not vectorized: Cannot fold tail by masking in the presence of live outs.38; instead.39define i64 @test1(i64 %y) {40; CHECK-LABEL: @test1(41; CHECK-NEXT: entry:42; CHECK-NEXT: br label [[VECTOR_PH:%.*]]43; CHECK: vector.ph:44; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i64> poison, i64 [[Y:%.*]], i64 045; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x i64> [[BROADCAST_SPLATINSERT]], <4 x i64> poison, <4 x i32> zeroinitializer46; CHECK-NEXT: [[TMP0:%.*]] = icmp eq <4 x i64> [[BROADCAST_SPLAT]], zeroinitializer47; CHECK-NEXT: [[TMP1:%.*]] = xor <4 x i64> splat (i64 3), [[BROADCAST_SPLAT]]48; CHECK-NEXT: [[TMP2:%.*]] = extractelement <4 x i1> [[TMP0]], i32 049; CHECK-NEXT: [[PREDPHI:%.*]] = select i1 [[TMP2]], <4 x i64> splat (i64 77), <4 x i64> [[TMP1]]50; CHECK-NEXT: br label [[FOR_BODY:%.*]]51; CHECK: vector.body:52; CHECK-NEXT: br label [[MIDDLE_BLOCK:%.*]]53; CHECK: middle.block:54; CHECK-NEXT: [[TMP3:%.*]] = call i64 @llvm.experimental.cttz.elts.i64.v4i1(<4 x i1> <i1 false, i1 false, i1 false, i1 true>, i1 false)55; CHECK-NEXT: [[TMP4:%.*]] = sub i64 [[TMP3]], 156; CHECK-NEXT: [[TMP5:%.*]] = extractelement <4 x i64> [[PREDPHI]], i64 [[TMP4]]57; CHECK-NEXT: br label [[COND_END:%.*]]58; CHECK: for.cond.cleanup:59; CHECK-NEXT: ret i64 [[TMP5]]60;61entry:62 br label %for.body63 64for.body:65 %i = phi i32 [ 0, %entry ], [ %inc, %cond.end ]66 %cmp = icmp eq i64 %y, 067 br i1 %cmp, label %cond.end, label %cond.false68 69cond.false:70 %div = xor i64 3, %y71 br label %cond.end72 73cond.end:74 %cond = phi i64 [ %div, %cond.false ], [ 77, %for.body ]75 %inc = add nuw nsw i32 %i, 176 %exitcond = icmp eq i32 %inc, 377 br i1 %exitcond, label %for.cond.cleanup, label %for.body78 79for.cond.cleanup:80 ret i64 %cond81}82 83; This test case miscompiled with clang 8.0.0 (see PR43166), now we get84; loop not vectorized: Cannot fold tail by masking in the presence of live outs.85; instead.86define i64 @test2(i64 %y) {87; CHECK-LABEL: @test2(88; CHECK-NEXT: entry:89; CHECK-NEXT: br label [[VECTOR_PH:%.*]]90; CHECK: vector.ph:91; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i64 [[Y:%.*]], 092; CHECK-NEXT: [[PREDPHI:%.*]] = select i1 [[TMP1]], <4 x i64> splat (i64 77), <4 x i64> splat (i64 55)93; CHECK-NEXT: br label [[FOR_BODY:%.*]]94; CHECK: vector.body:95; CHECK-NEXT: br label [[MIDDLE_BLOCK:%.*]]96; CHECK: middle.block:97; CHECK-NEXT: [[TMP2:%.*]] = call i64 @llvm.experimental.cttz.elts.i64.v4i1(<4 x i1> <i1 false, i1 false, i1 false, i1 true>, i1 false)98; CHECK-NEXT: [[TMP3:%.*]] = sub i64 [[TMP2]], 199; CHECK-NEXT: [[TMP4:%.*]] = extractelement <4 x i64> [[PREDPHI]], i64 [[TMP3]]100; CHECK-NEXT: br label [[COND_END:%.*]]101; CHECK: for.cond.cleanup:102; CHECK-NEXT: ret i64 [[TMP4]]103;104entry:105 br label %for.body106 107for.body:108 %i = phi i32 [ 0, %entry ], [ %inc, %cond.end ]109 %cmp = icmp eq i64 %y, 0110 br i1 %cmp, label %cond.end, label %cond.false111 112cond.false:113 br label %cond.end114 115cond.end:116 %cond = phi i64 [ 55, %cond.false ], [ 77, %for.body ]117 %inc = add nuw nsw i32 %i, 1118 %exitcond = icmp eq i32 %inc, 3119 br i1 %exitcond, label %for.cond.cleanup, label %for.body120 121for.cond.cleanup:122 ret i64 %cond123}124 125; This test case miscompiled with clang 8.0.0 (see PR43166), now we get126; loop not vectorized: Cannot fold tail by masking in the presence of live outs.127; instead.128define i32 @test3(i64 %y) {129; CHECK-LABEL: @test3(130; CHECK-NEXT: entry:131; CHECK-NEXT: br label [[VECTOR_PH:%.*]]132; CHECK: vector.ph:133; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i64 [[Y:%.*]], 0134; CHECK-NEXT: br label [[FOR_BODY:%.*]]135; CHECK: vector.body:136; CHECK-NEXT: [[PREDPHI:%.*]] = select i1 [[TMP1]], <4 x i32> <i32 0, i32 1, i32 2, i32 3>, <4 x i32> splat (i32 55)137; CHECK-NEXT: br label [[MIDDLE_BLOCK:%.*]]138; CHECK: middle.block:139; CHECK-NEXT: [[TMP2:%.*]] = call i64 @llvm.experimental.cttz.elts.i64.v4i1(<4 x i1> <i1 false, i1 false, i1 false, i1 true>, i1 false)140; CHECK-NEXT: [[TMP3:%.*]] = sub i64 [[TMP2]], 1141; CHECK-NEXT: [[TMP4:%.*]] = extractelement <4 x i32> [[PREDPHI]], i64 [[TMP3]]142; CHECK-NEXT: br label [[COND_END:%.*]]143; CHECK: for.cond.cleanup:144; CHECK-NEXT: ret i32 [[TMP4]]145;146entry:147 br label %for.body148 149for.body:150 %i = phi i32 [ 0, %entry ], [ %inc, %cond.end ]151 %cmp = icmp eq i64 %y, 0152 br i1 %cmp, label %cond.end, label %cond.false153 154cond.false:155 br label %cond.end156 157cond.end:158 %cond = phi i32 [ 55, %cond.false ], [ %i, %for.body ]159 %inc = add nuw nsw i32 %i, 1160 %exitcond = icmp eq i32 %inc, 3161 br i1 %exitcond, label %for.cond.cleanup, label %for.body162 163for.cond.cleanup:164 ret i32 %cond165}166