Skip to content

Commit ff36ec6

Browse files
author
Patrick Häcker
committed
Increase robustness of LLVM tests by renumbering SSAs
1 parent 340d4f7 commit ff36ec6

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

test/runtests.jl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,14 @@ end
543543
# A `call` instruction targeting an LLVM intrinsic (`@llvm.ctpop`, `@llvm.abs`, …) is a single native instruction, not a runtime dispatch. Only flag calls into Julia runtime functions (`@j_*`, `@julia_*`, `@ijl_*`, `@jl_*`).
544544
runtime_calls(ops) = count(l -> occursin("call ", l) && !occursin("@llvm.", l), ops)
545545

546+
# Unnamed SSA values (`%16`, `%11`, …) are numbered sequentially across the whole function, so the same operation sequence picks up different numbers depending on how much unrelated code precedes it (coverage counters, surrounding context). Renumber each distinct `%<n>` by order of first appearance so equality checks compare structure and data flow rather than absolute ids. Named values like `%"x::Int3"` have no digit right after `%` and are left untouched.
547+
function normalize_ssa(ops)
548+
mapping = Dict{String, Int}()
549+
map(ops) do l
550+
replace(l, r"%\d+" => m -> "%" * string(get!(mapping, m, length(mapping))))
551+
end
552+
end
553+
546554
@testset "performance invariants" begin
547555
using InteractiveUtils
548556
@emulate UInt3 Int3 UInt20
@@ -584,10 +592,10 @@ runtime_calls(ops) = count(l -> occursin("call ", l) && !occursin("@llvm.", l),
584592
VERSION >= v"1.11" && @test length(ops) == exact_ops
585593
end
586594

587-
@test llvm_ops(le_uint_2, Tuple{UInt}) == llvm_ops(le_int_2, Tuple{UInt})
588-
@test llvm_ops(le_int3_2, Tuple{Int3}) == llvm_ops(le_int3_int_2, Tuple{Int3})
589-
@test llvm_ops(le_uint3_2, Tuple{UInt3}) == llvm_ops(le_uint3_int_2, Tuple{UInt3})
590-
@test llvm_ops(le_uint_typemax_int, Tuple{UInt}) == llvm_ops(le_int_typemax_int, Tuple{UInt})
595+
@test normalize_ssa(llvm_ops(le_uint_2, Tuple{UInt})) == normalize_ssa(llvm_ops(le_int_2, Tuple{UInt}))
596+
@test normalize_ssa(llvm_ops(le_int3_2, Tuple{Int3})) == normalize_ssa(llvm_ops(le_int3_int_2, Tuple{Int3}))
597+
@test normalize_ssa(llvm_ops(le_uint3_2, Tuple{UInt3})) == normalize_ssa(llvm_ops(le_uint3_int_2, Tuple{UInt3}))
598+
@test normalize_ssa(llvm_ops(le_uint_typemax_int, Tuple{UInt})) == normalize_ssa(llvm_ops(le_int_typemax_int, Tuple{UInt}))
591599
end
592600

593601

0 commit comments

Comments
 (0)