Alive2 consists of several libraries and tools for analysis and verification
of LLVM code and transformations.
This fork is modified to pre-convert the SWPP2022-specific intrinsics.
See here for the original repo
Alive2 does not support inter-procedural transformations. Alive2 may crash or produce spurious counterexamples if run with such passes.
To build Alive2 you need recent versions of:
- cmake
- gcc/clang
- re2c
- Z3
- LLVM (With RTTI and exception handling enabled: the build script in class repo already does that)
Use the build.sh
to build alive-tv. Default LLVM_DIR and Z3_DIR should work
for the default CI docker image.
This tool has two modes.
In the first mode, specify a source (original) and target (optimized)
IR file. For example, let's prove that removing nsw
is correct
for addition:
$ ./alive-tv src.ll tgt.ll
----------------------------------------
define i32 @f(i32 %a, i32 %b) {
%add = add nsw i32 %b, %a
ret i32 %add
}
=>
define i32 @f(i32 %a, i32 %b) {
%add = add i32 %b, %a
ret i32 %add
}
Transformation seems to be correct!
Flipping the inputs yields a counterexample, since it's not correct, in general,
to add nsw
.
If you are not interested in counterexamples using undef
, you can use the
command-line argument -disable-undef-input
.
In the second mode, specify a single unoptimized IR file. alive-tv will optimize it using an optimization pipeline similar to -O2, but without any interprocedural passes, and then attempt to validate the translation.
For example, as of February 6 2020, the release/10.x
branch contains
an optimizer bug that can be triggered as follows:
$ cat foo.ll
define i3 @foo(i3) {
%x1 = sub i3 0, %0
%x2 = icmp ne i3 %0, 0
%x3 = zext i1 %x2 to i3
%x4 = lshr i3 %x1, %x3
%x5 = lshr i3 %x4, %x3
ret i3 %x5
}
$ ./alive-tv foo.ll
----------------------------------------
define i3 @foo(i3 %0) {
%x1 = sub i3 0, %0
%x2 = icmp ne i3 %0, 0
%x3 = zext i1 %x2 to i3
%x4 = lshr i3 %x1, %x3
%x5 = lshr i3 %x4, %x3
ret i3 %x5
}
=>
define i3 @foo(i3 %0) {
%x1 = sub i3 0, %0
ret i3 %x1
}
Transformation doesn't verify!
ERROR: Value mismatch
Example:
i3 %0 = #x5 (5, -3)
Source:
i3 %x1 = #x3 (3)
i1 %x2 = #x1 (1)
i3 %x3 = #x1 (1)
i3 %x4 = #x1 (1)
i3 %x5 = #x0 (0)
Target:
i3 %x1 = #x3 (3)
Source value: #x0 (0)
Target value: #x3 (3)
Summary:
0 correct transformations
1 incorrect transformations
0 errors