Skip to content

Commit

Permalink
Fix tests and static analyzer for LLVM 15
Browse files Browse the repository at this point in the history
Co-authored-by: Gabriel Baraldi <[email protected]>
Co-authored-by: Prem Chintalapudi <[email protected]>
  • Loading branch information
3 people committed May 10, 2023
1 parent 9e3da19 commit 2ddbb5a
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 35 deletions.
3 changes: 3 additions & 0 deletions src/llvm-alloc-opt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1138,9 +1138,12 @@ void Optimizer::splitOnStack(CallInst *orig_inst)
ref->setOrdering(AtomicOrdering::NotAtomic);
operands.push_back(ref);
}
#ifndef __clang_analyzer__
// FIXME: SA finds "Called C++ object pointer is null" inside the LLVM code.
auto new_call = builder.CreateCall(pass.gc_preserve_begin_func, operands);
new_call->takeName(call);
call->replaceAllUsesWith(new_call);
#endif
call->eraseFromParent();
return;
}
Expand Down
1 change: 1 addition & 0 deletions src/llvm-late-gc-lowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,7 @@ static bool isLoadFromConstGV(LoadInst *LI, bool &task_local, PhiSet *seen)
// We only emit single slot GV in codegen
// but LLVM global merging can change the pointer operands to GEPs/bitcasts
auto load_base = LI->getPointerOperand()->stripInBoundsOffsets();
assert(load_base); // Static analyzer
auto gv = dyn_cast<GlobalVariable>(load_base);
if (isTBAA(LI->getMetadata(LLVMContext::MD_tbaa),
{"jtbaa_immut", "jtbaa_const", "jtbaa_datatype"})) {
Expand Down
1 change: 1 addition & 0 deletions src/llvm-lower-handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <llvm/ADT/DepthFirstIterator.h>
#include <llvm/ADT/Statistic.h>
#include <llvm/ADT/Triple.h>
#include <llvm/Analysis/CFG.h>
#include <llvm/IR/BasicBlock.h>
#include <llvm/IR/Constants.h>
Expand Down
3 changes: 3 additions & 0 deletions src/llvm-multiversioning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
#include <llvm/Pass.h>
#include <llvm/ADT/BitVector.h>
#include <llvm/ADT/Statistic.h>
#include <llvm/ADT/Triple.h>
#include <llvm/IR/Module.h>
#include <llvm/IR/LegacyPassManager.h>
#include <llvm/IR/Function.h>
#include <llvm/IR/Instructions.h>
#include <llvm/IR/Constants.h>
#include <llvm/IR/Dominators.h>
#include <llvm/IR/LLVMContext.h>
#include <llvm/Analysis/LoopInfo.h>
#include <llvm/Analysis/CallGraph.h>
Expand Down Expand Up @@ -779,6 +781,7 @@ static Value *rewrite_inst_use(const Stack& stack, Type *T_size, Value *replace,
replace = inst;
continue;
}
assert(val);
unsigned nargs = val->getNumOperands();
args.resize(nargs);
for (unsigned j = 0; j < nargs; j++) {
Expand Down
2 changes: 2 additions & 0 deletions src/llvm-ptls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <llvm-c/Types.h>

#include <llvm/Pass.h>
#include <llvm/ADT/Triple.h>
#include <llvm/IR/Module.h>
#include <llvm/IR/LegacyPassManager.h>
#include <llvm/IR/Function.h>
Expand Down Expand Up @@ -161,6 +162,7 @@ void LowerPTLS::fix_pgcstack_use(CallInst *pgcstack, Function *pgcstack_getter,
SmallVector<uint32_t, 2> Weights{9, 1};
TerminatorInst *fastTerm;
TerminatorInst *slowTerm;
assert(pgcstack->getType()); // Static analyzer
auto cmp = new ICmpInst(phi, CmpInst::ICMP_NE, pgcstack, Constant::getNullValue(pgcstack->getType()));
SplitBlockAndInsertIfThenElse(cmp, phi, &fastTerm, &slowTerm,
MDB.createBranchWeights(Weights));
Expand Down
3 changes: 3 additions & 0 deletions test/clangsa/MissingRoots.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,9 @@ void assoc_exact_broken(jl_value_t **args, size_t n, int8_t offs, size_t world)
}
*/

// declare
jl_typemap_level_t *jl_new_typemap_level(void);

void assoc_exact_ok(jl_value_t *args1, jl_value_t **args, size_t n, int8_t offs, size_t world) {
jl_typemap_level_t *cache = jl_new_typemap_level();
JL_GC_PUSH1(&cache);
Expand Down
10 changes: 6 additions & 4 deletions test/cmdlineargs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,12 @@ let exename = `$(Base.julia_cmd()) --startup-file=no --color=no`
@test contains(v[2], r"enable-tail-merge + = 1")
@test isempty(v[3])
end
@testset let v = readchomperrors(setenv(`$exename -e 0`, "JULIA_LLVM_ARGS" => "-print-options -enable-tail-merge=1 -enable-tail-merge=1", "HOME" => homedir()))
@test !v[1]
@test isempty(v[2])
@test v[3] == "julia: for the --enable-tail-merge option: may only occur zero or one times!"
if Base.libllvm_version < v"15" #LLVM over 15 doesn't care for multiple options
@testset let v = readchomperrors(setenv(`$exename -e 0`, "JULIA_LLVM_ARGS" => "-print-options -enable-tail-merge=1 -enable-tail-merge=1", "HOME" => homedir()))
@test !v[1]
@test isempty(v[2])
@test v[3] == "julia: for the --enable-tail-merge option: may only occur zero or one times!"
end
end
end

Expand Down
68 changes: 40 additions & 28 deletions test/llvmpasses/pipeline-o2-broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,30 @@ include(joinpath("..", "testhelpers", "llvmpasses.jl"))

# COM: Float32
# CHECK: @japi1_prod_v_vT
# CHECK: load <[[VSCALE:(vscale x )?]][[VEC_FACTOR:[0-9]+]] x float>
# CHECK: fmul <[[VSCALE]][[VEC_FACTOR]] x float>
# COM: load <[[VSCALE:(vscale x )?]][[VEC_FACTOR:[0-9]+]] x float>
# COM: fmul <[[VSCALE]][[VEC_FACTOR]] x float>
# CHECK: fmul <[[VSCALE:(vscale x )?]][[VEC_FACTOR:[0-9]+]] x float>
# CHECK: store <[[VSCALE]][[VEC_FACTOR]] x float>

# COM: Float64
# CHECK: @japi1_prod_v_vT
# CHECK: load <[[VSCALE:(vscale x )?]][[VEC_FACTOR:[0-9]+]] x double>
# CHECK: fmul <[[VSCALE]][[VEC_FACTOR]] x double>
# COM: load <[[VSCALE:(vscale x )?]][[VEC_FACTOR:[0-9]+]] x double>
# COM: fmul <[[VSCALE]][[VEC_FACTOR]] x double>
# CHECK: fmul <[[VSCALE:(vscale x )?]][[VEC_FACTOR:[0-9]+]] x double>
# CHECK: store <[[VSCALE]][[VEC_FACTOR]] x double>

# COM: Int32
# CHECK: @japi1_prod_v_vT
# CHECK: load <[[VSCALE:(vscale x )?]][[VEC_FACTOR:[0-9]+]] x i32>
# CHECK: mul <[[VSCALE]][[VEC_FACTOR]] x i32>
# COM: load <[[VSCALE:(vscale x )?]][[VEC_FACTOR:[0-9]+]] x i32>
# COM: mul <[[VSCALE]][[VEC_FACTOR]] x i32>
# CHECK: mul <[[VSCALE:(vscale x )?]][[VEC_FACTOR:[0-9]+]] x i32>
# CHECK: store <[[VSCALE]][[VEC_FACTOR]] x i32>

# COM: Int64
# CHECK: @japi1_prod_v_vT
# CHECK: load <[[VSCALE:(vscale x )?]][[VEC_FACTOR:[0-9]+]] x i64>
# CHECK: mul <[[VSCALE]][[VEC_FACTOR]] x i64>
# COM: load <[[VSCALE:(vscale x )?]][[VEC_FACTOR:[0-9]+]] x i64>
# COM: mul <[[VSCALE]][[VEC_FACTOR]] x i64>
# CHECK: mul <[[VSCALE:(vscale x )?]][[VEC_FACTOR:[0-9]+]] x i64>
# CHECK: store <[[VSCALE]][[VEC_FACTOR]] x i64>

function prod_v_vT(R, x, y)
Expand All @@ -39,26 +43,30 @@ end

# COM: Float32
# CHECK: @japi1_prod_vT_v
# CHECK: load <[[VSCALE:(vscale x )?]][[VEC_FACTOR:[0-9]+]] x float>
# CHECK: fmul <[[VSCALE]][[VEC_FACTOR]] x float>
# COM: load <[[VSCALE:(vscale x )?]][[VEC_FACTOR:[0-9]+]] x float>
# COM: fmul <[[VSCALE]][[VEC_FACTOR]] x float>
# CHECK: fmul <[[VSCALE:(vscale x )?]][[VEC_FACTOR:[0-9]+]] x float>
# CHECK: store <[[VSCALE]][[VEC_FACTOR]] x float>

# COM: Float64
# CHECK: @japi1_prod_vT_v
# CHECK: load <[[VSCALE:(vscale x )?]][[VEC_FACTOR:[0-9]+]] x double>
# CHECK: fmul <[[VSCALE]][[VEC_FACTOR]] x double>
# COM: load <[[VSCALE:(vscale x )?]][[VEC_FACTOR:[0-9]+]] x double>
# COM: fmul <[[VSCALE]][[VEC_FACTOR]] x double>
# CHECK: fmul <[[VSCALE:(vscale x )?]][[VEC_FACTOR:[0-9]+]] x double>
# CHECK: store <[[VSCALE]][[VEC_FACTOR]] x double>

# COM: Int32
# CHECK: @japi1_prod_vT_v
# CHECK: load <[[VSCALE:(vscale x )?]][[VEC_FACTOR:[0-9]+]] x i32>
# CHECK: mul <[[VSCALE]][[VEC_FACTOR]] x i32>
# COM: load <[[VSCALE:(vscale x )?]][[VEC_FACTOR:[0-9]+]] x i32>
# COM: mul <[[VSCALE]][[VEC_FACTOR]] x i32>
# CHECK: mul <[[VSCALE:(vscale x )?]][[VEC_FACTOR:[0-9]+]] x i32>
# CHECK: store <[[VSCALE]][[VEC_FACTOR]] x i32>

# COM: Int64
# CHECK: @japi1_prod_vT_v
# CHECK: load <[[VSCALE:(vscale x )?]][[VEC_FACTOR:[0-9]+]] x i64>
# CHECK: mul <[[VSCALE]][[VEC_FACTOR]] x i64>
# COM: load <[[VSCALE:(vscale x )?]][[VEC_FACTOR:[0-9]+]] x i64>
# COM: mul <[[VSCALE]][[VEC_FACTOR]] x i64>
# CHECK: mul <[[VSCALE:(vscale x )?]][[VEC_FACTOR:[0-9]+]] x i64>
# CHECK: store <[[VSCALE]][[VEC_FACTOR]] x i64>

function prod_vT_v(R, x, y)
Expand All @@ -69,27 +77,31 @@ end

# COM: Float32
# CHECK: @japi1_prod_v_M_vT
# CHECK: load <[[VSCALE:(vscale x )?]][[VEC_FACTOR:[0-9]+]] x float>
# CHECK: fmul <[[VSCALE]][[VEC_FACTOR]] x float>
# CHECK: store <[[VSCALE]][[VEC_FACTOR]] x float>
# COM: load <[[VSCALE:(vscale x )?]][[VEC_FACTOR:[0-9]+]] x float>
# COM: fmul <[[VSCALE]][[VEC_FACTOR]] x float>
# XFAIL-CHECK: fmul <[[VSCALE:(vscale x )?]][[VEC_FACTOR:[0-9]+]] x float>
# XFAIL-CHECK: store <[[VSCALE]][[VEC_FACTOR]] x float>

# COM: Float64
# CHECK: @japi1_prod_v_M_vT
# CHECK: load <[[VSCALE:(vscale x )?]][[VEC_FACTOR:[0-9]+]] x double>
# CHECK: fmul <[[VSCALE]][[VEC_FACTOR]] x double>
# CHECK: store <[[VSCALE]][[VEC_FACTOR]] x double>
# COM: load <[[VSCALE:(vscale x )?]][[VEC_FACTOR:[0-9]+]] x double>
# COM: fmul <[[VSCALE]][[VEC_FACTOR]] x double>
# XFAIL-CHECK: fmul <[[VSCALE:(vscale x )?]][[VEC_FACTOR:[0-9]+]] x double>
# XFAIL-CHECK: store <[[VSCALE]][[VEC_FACTOR]] x double>

# COM: Int32
# CHECK: @japi1_prod_v_M_vT
# CHECK: load <[[VSCALE:(vscale x )?]][[VEC_FACTOR:[0-9]+]] x i32>
# CHECK: mul <[[VSCALE]][[VEC_FACTOR]] x i32>
# CHECK: store <[[VSCALE]][[VEC_FACTOR]] x i32>
# COM: load <[[VSCALE:(vscale x )?]][[VEC_FACTOR:[0-9]+]] x i32>
# COM: mul <[[VSCALE]][[VEC_FACTOR]] x i32>
# XFAIL-CHECK: mul <[[VSCALE:(vscale x )?]][[VEC_FACTOR:[0-9]+]] x i32>
# XFAIL-CHECK: store <[[VSCALE]][[VEC_FACTOR]] x i32>

# COM: Int64
# CHECK: @japi1_prod_v_M_vT
# CHECK: load <[[VSCALE:(vscale x )?]][[VEC_FACTOR:[0-9]+]] x i64>
# CHECK: mul <[[VSCALE]][[VEC_FACTOR]] x i64>
# CHECK: store <[[VSCALE]][[VEC_FACTOR]] x i64>
# COM: load <[[VSCALE:(vscale x )?]][[VEC_FACTOR:[0-9]+]] x i64>
# COM: mul <[[VSCALE]][[VEC_FACTOR]] x i64>
# XFAIL-CHECK: mul <[[VSCALE:(vscale x )?]][[VEC_FACTOR:[0-9]+]] x i64>
# XFAIL-CHECK: store <[[VSCALE]][[VEC_FACTOR]] x i64>

function prod_v_M_vT(R, x, M, y)
R .= x .* M .* y'
Expand Down
6 changes: 3 additions & 3 deletions test/llvmpasses/pipeline-o2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,21 @@ end
# COM: memset checks

# COM: INT64
# ALL-LABEL: define nonnull {} addrspace(10)* @julia_zeros
# ALL: define {{.*}} @julia_zeros
# ALL-NOT: bounds_error
# COM: memset is not used with bounds checks on (too late in the pipeline)
# BC_OFF: llvm.memset
# BC_AUTO: llvm.memset

# COM: INT32
# ALL-LABEL: define nonnull {} addrspace(10)* @julia_zeros
# ALL: define {{.*}} @julia_zeros
# ALL-NOT: bounds_error
# COM: memset is not used with bounds checks on (too late in the pipeline)
# BC_OFF: llvm.memset
# BC_AUTO: llvm.memset

# COM: INT16
# ALL-LABEL: define nonnull {} addrspace(10)* @julia_zeros
# ALL: define {{.*}} @julia_zeros
# ALL-NOT: bounds_error
# COM: memset is not used with bounds checks on (too late in the pipeline)
# BC_OFF: llvm.memset
Expand Down

0 comments on commit 2ddbb5a

Please sign in to comment.