Skip to content

Crash when running supervec at a specific optimization level #4

@Stefan-Mada

Description

@Stefan-Mada

I made a function that runs gracefully when compiled with -O0, -O2, -O3, and -Ofast, but crashes when it's compiled with -O1.

Source file:

#include <immintrin.h>

int function(__m256i vec)
{	
	int64_t* arr = (int64_t*)&vec;
	int sum = 0;
	for(int i = 0; i < 4; ++i)
		sum += arr[i];
	return sum;
}

Compiled using:
clang++ -I -march=native -mavx2 -O1 -Werror -S -emit-llvm function.cpp -o function.ll

Called supervec using:
$HOME/llvm/build/bin/opt -enable-new-pm=0 -load $HOME/minotaur/build/minotaur.so -so -S function.ll


Sketches output:
---------Sketches------------
(copy reservedconst)
(and %, %)
(and %, %)
(and %, reservedconst)
(and %, %)
(and %, reservedconst)
(or %, %)
(or %, %)
(or %, reservedconst)
(or %, %)
(or %, reservedconst)
(xor %, %)
(xor %, %)
(xor %, reservedconst)
(xor %, %)
(xor %, reservedconst)
(add %, %)
(add %, %)
(add %, reservedconst)
(add %, %)
(add %, reservedconst)
(sub %, %)
(sub %, %)
(sub %, %)
(sub %, %)
(sub reservedconst, %)
(sub reservedconst, %)
(mul %, %)
(mul %, %)
(mul %, reservedconst)
(mul %, %)
(mul %, reservedconst)
%
%
(load)
-----------------------------

----------------------------------------
define i32 @_Z8functionDv4_x.75.76(<4 x i64> %0, i64 %_reservedc_0) noread nowrite nofree {
%1:
  %4 = alloca i64 32, align 32
  store <4 x i64> %0, * %4, align 32
  br label %2

%2:
  %5 = phi i64 [ 0, %1 ], [ %11, %2 ]
  %6 = phi i32 [ 0, %1 ], [ %10, %2 ]
  %7 = gep inbounds * %4, 32 x i64 0, 8 x i64 %5
  %8 = load i64, * %7, align 8
  %9 = trunc i64 %8 to i32
  %10 = add i32 %6, %9
  %11 = add nsw nuw i64 %5, 1
  %12 = icmp eq i64 %11, 4
  br i1 %12, label %3, label %2#2

%2#2:
  %5#2 = phi i64 [ %11, %2 ]
  %6#2 = phi i32 [ %10, %2 ]
  %7#2 = gep inbounds * %4, 32 x i64 0, 8 x i64 %5#2
  %8#2 = load i64, * %7#2, align 8
  %9#2 = trunc i64 %8#2 to i32
  %10#2 = add i32 %6#2, %9#2
  %11#2 = add nsw nuw i64 %5#2, 1
  %12#2 = icmp eq i64 %11#2, 4
  br i1 %12#2, label %3, label #sink

%3:
  %10#phi#0 = phi i32 [ %10, %2 ], [ %10#2, %2#2 ]
  ret i32 %10#phi#0
}
=>
define i32 @_Z8functionDv4_x.75(<4 x i64> %0, i64 %_reservedc_0) noread nowrite nofree {
%1:
  %4 = alloca i64 32, align 32
  store <4 x i64> %0, * %4, align 32
  br label %2

%2:
  %5 = phi i64 [ 0, %1 ], [ %9, %2 ]
  %6 = phi i32 [ 0, %1 ], [ %8, %2 ]
  %7 = trunc i64 %_reservedc_0 to i32
  %8 = add i32 %6, %7
  %9 = add nsw nuw i64 %5, 1
  %10 = icmp eq i64 %9, 4
  br i1 %10, label %3, label %2#2

%2#2:
  %5#2 = phi i64 [ %9, %2 ]
  %6#2 = phi i32 [ %8, %2 ]
  %7#2 = trunc i64 %_reservedc_0 to i32
  %8#2 = add i32 %6#2, %7#2
  %9#2 = add nsw nuw i64 %5#2, 1
  %10#2 = icmp eq i64 %9#2, 4
  br i1 %10#2, label %3, label #sink

%3:
  %8#phi#0 = phi i32 [ %8, %2 ], [ %8#2, %2#2 ]
  ret i32 %8#phi#0
}
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0.	Program arguments: /home/stefan/llvm/build/bin/opt -enable-new-pm=0 -load /home/stefan/minotaur/build/minotaur.so -so -S function.ll
1.	Running pass 'Function Pass Manager' on module 'function.ll'.
2.	Running pass 'Superoptimizer' on function '@_Z8functionDv4_x'
 #0 0x00007f9404f57c14 PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
 #1 0x00007f9404f54c9e SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f9404991210 (/lib/x86_64-linux-gnu/libc.so.6+0x46210)
 #3 0x00007f9404c8cf1d std::ostream::sentry::sentry(std::ostream&) (/lib/x86_64-linux-gnu/libstdc++.so.6+0x132f1d)
 #4 0x00007f9404c8d6cc std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long) (/lib/x86_64-linux-gnu/libstdc++.so.6+0x1336cc)
 #5 0x00007f94036825a8 (anonymous namespace)::llvm2alive_::visitCastInst(llvm::CastInst&) llvm2alive.cpp:0:0
 #6 0x00007f9403689738 llvm::InstVisitor<(anonymous namespace)::llvm2alive_, std::unique_ptr<IR::Instr, std::default_delete<IR::Instr> > >::visit(llvm::Instruction&) llvm2alive.cpp:0:0
 #7 0x00007f940368f180 (anonymous namespace)::llvm2alive_::run() llvm2alive.cpp:0:0
 #8 0x00007f940369044e llvm_util::llvm2alive(llvm::Function&, llvm::TargetLibraryInfo const&, std::vector<std::basic_string_view<char, std::char_traits<char> >, std::allocator<std::basic_string_view<char, std::char_traits<char> > > > const&) (/home/stefan/minotaur/build/minotaur.so+0x13a44e)
 #9 0x00007f94035cfc7b minotaur::synthesize(llvm::Function&, llvm::TargetLibraryInfo*) (/home/stefan/minotaur/build/minotaur.so+0x79c7b)
#10 0x00007f940525d7d3 llvm::FPPassManager::runOnFunction(llvm::Function&) (/home/stefan/llvm/build/bin/../lib/libLLVMCore.so.14git+0x2727d3)
#11 0x00007f940525da19 llvm::FPPassManager::runOnModule(llvm::Module&) (/home/stefan/llvm/build/bin/../lib/libLLVMCore.so.14git+0x272a19)
#12 0x00007f940525ec23 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/stefan/llvm/build/bin/../lib/libLLVMCore.so.14git+0x273c23)
#13 0x0000565019999fc4 main (/home/stefan/llvm/build/bin/opt+0x27fc4)
#14 0x00007f94049720b3 __libc_start_main /build/glibc-eX1tMB/glibc-2.31/csu/../csu/libc-start.c:342:3
#15 0x000056501999ae7e _start (/home/stefan/llvm/build/bin/opt+0x28e7e)
Segmentation fault (core dumped)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions