-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Closed
Labels
Description
Bugzilla Link | 52335 |
Version | trunk |
OS | Linux |
CC | @dbabokin,@topperc,@RKSimon,@phoebewang,@regehr,@rotateright,@Vsevolod-Livinskij |
Extended Description
It looks like LoopVectorizePass introduces changes that uncover a bug in the backend. The transformation was verified with alive2. I've attached C++ and LLVM IR reproducers.
C++ reproducer:
// func.cpp
extern int var_3;
extern bool var_23;
extern int arr_12[];
extern short arr_13[];
void test() {
#pragma clang loop vectorize_predicate(enable)
for (char a = 4; a < var_3; a++) {
arr_13[a] = arr_12[a - 3];
var_23 = arr_12[a - 1];
}
}
// driver.cpp
#include <stdio.h>
int var_3 = 24;
bool var_23 = 1;
int arr_12 [25];
unsigned short arr_13 [25];
void test();
int main() {
for (size_t i_0 = 0; i_0 < 25; ++i_0)
arr_12 [i_0] = 1;
test();
printf("%d\n", (int)var_23);
}
$ clang++ -O0 -march=skx func.cpp driver.cpp && sde -skx -- ./a.out
1
$ clang++ -O1 -march=skx func.cpp driver.cpp && sde -skx -- ./a.out
0
LLVM IR Reproducer:
; ModuleID = 'func.cpp'
source_filename = "func.cpp"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
@var_3 = external dso_local local_unnamed_addr global i32, align 4
@arr_12 = external dso_local local_unnamed_addr global [0 x i32], align 4
@arr_13 = external dso_local local_unnamed_addr global [0 x i16], align 2
@var_23 = external dso_local local_unnamed_addr global i8, align 1
; Function Attrs: mustprogress nofree norecurse nosync nounwind uwtable
define dso_local void @_Z4testv() local_unnamed_addr #0 {
entry:
%0 = load i32, i32* @var_3, align 4, !tbaa !3
%cmp13 = icmp sgt i32 %0, 4
br i1 %cmp13, label %for.body.preheader, label %for.cond.cleanup
for.body.preheader: ; preds = %entry
br label %for.body
for.cond.for.cond.cleanup_crit_edge: ; preds = %for.body
%conv15.lcssa = phi i32 [ %conv15, %for.body ]
%sub6 = add nsw i32 %conv15.lcssa, -1
%idxprom7 = sext i32 %sub6 to i64
%arrayidx8 = getelementptr inbounds [0 x i32], [0 x i32]* @arr_12, i64 0, i64 %idxprom7
%1 = load i32, i32* %arrayidx8, align 4, !tbaa !3
%tobool = icmp ne i32 %1, 0
%frombool = zext i1 %tobool to i8
store i8 %frombool, i8* @var_23, align 1, !tbaa !7
br label %for.cond.cleanup
for.cond.cleanup: ; preds = %for.cond.for.cond.cleanup_crit_edge, %entry
ret void
for.body: ; preds = %for.body.preheader, %for.body
%conv15 = phi i32 [ %conv, %for.body ], [ 4, %for.body.preheader ]
%a.014 = phi i8 [ %inc, %for.body ], [ 4, %for.body.preheader ]
%sub = add nsw i32 %conv15, -3
%idxprom = sext i32 %sub to i64
%arrayidx = getelementptr inbounds [0 x i32], [0 x i32]* @arr_12, i64 0, i64 %idxprom
%2 = load i32, i32* %arrayidx, align 4, !tbaa !3
%conv2 = trunc i32 %2 to i16
%idxprom3 = sext i8 %a.014 to i64
%arrayidx4 = getelementptr inbounds [0 x i16], [0 x i16]* @arr_13, i64 0, i64 %idxprom3
store i16 %conv2, i16* %arrayidx4, align 2, !tbaa !9
%inc = add i8 %a.014, 1
%conv = sext i8 %inc to i32
%cmp = icmp sgt i32 %0, %conv
br i1 %cmp, label %for.body, label %for.cond.for.cond.cleanup_crit_edge, !llvm.loop !11
}
attributes #0 = { mustprogress nofree norecurse nosync nounwind uwtable "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="skx" "target-features"="+adx,+aes,+avx,+avx2,+avx512bw,+avx512cd,+avx512dq,+avx512f,+avx512vl,+bmi,+bmi2,+clflushopt,+clwb,+crc32,+cx16,+cx8,+f16c,+fma,+fsgsbase,+fxsr,+invpcid,+lzcnt,+mmx,+movbe,+pclmul,+pku,+popcnt,+prfchw,+rdrnd,+rdseed,+sahf,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave,+xsavec,+xsaveopt,+xsaves" }
!llvm.module.flags = !{#0, !​1}
!llvm.ident = !{#2}
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 7, !"uwtable", i32 1}
!2 = !{!"clang version 14.0.0 (https://github.com/llvm/llvm-project.git 2d77b272a8f9b5b89b022628ca30b6b896a8f725)"}
!3 = !{#4, !4, i64 0}
!4 = !{!"int", !5, i64 0}
!5 = !{!"omnipotent char", !6, i64 0}
!6 = !{!"Simple C++ TBAA"}
!7 = !{#8, !8, i64 0}
!8 = !{!"bool", !5, i64 0}
!9 = !{#10, !10, i64 0}
!10 = !{!"short", !5, i64 0}
!11 = distinct !{#11, !12, !13, !14, !15}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!"llvm.loop.unroll.disable"}
!14 = !{!"llvm.loop.vectorize.predicate.enable", i1 true}
!15 = !{!"llvm.loop.vectorize.enable", i1 true}
$ clang++ -O0 ok.ll driver.cpp && sde -skx -- ./a.out
1
$ opt -loop-vectorize ok.ll > opt.ll && clang++ -O0 opt.ll driver.cpp && sde -skx -- ./a.out
0
LLVM version:
clang version 14.0.0 (https://github.com/llvm/llvm-project.git 2d77b27)