-
- Downloads
gimple ssa: Don't use __builtin_popcount in switch exp transform [PR116616]
Switch exponential transformation in the switch conversion pass
currently generates
tmp1 = __builtin_popcount (var);
tmp2 = tmp1 == 1;
when inserting code to determine if var is power of two. If the target
doesn't support expanding the builtin as special instructions switch
conversion relies on this whole pattern being expanded as bitmagic.
However, it is possible that other GIMPLE optimizations move the two
statements of the pattern apart. In that case the builtin becomes a
libgcc call in the final binary. The call is slow and in case of
freestanding programs can result in linking error (this bug was
originally found while compiling Linux kernel).
This patch modifies switch conversion to insert the bitmagic
(var ^ (var - 1)) > (var - 1) instead of the builtin.
gcc/ChangeLog:
PR tree-optimization/116616
* tree-switch-conversion.cc (can_pow2p): Remove this function.
(gen_pow2p): Generate bitmagic instead of a builtin. Remove the
TYPE parameter.
(switch_conversion::is_exp_index_transform_viable): Don't call
can_pow2p.
(switch_conversion::exp_index_transform): Call gen_pow2p without
the TYPE parameter.
* tree-switch-conversion.h: Remove
m_exp_index_transform_pow2p_type.
gcc/testsuite/ChangeLog:
PR tree-optimization/116616
* gcc.target/i386/switch-exp-transform-1.c: Don't test for
presence of the POPCOUNT internal fn call.
Signed-off-by:
Filip Kastl <fkastl@suse.cz>
Showing
- gcc/testsuite/gcc.target/i386/switch-exp-transform-1.c 2 additions, 5 deletionsgcc/testsuite/gcc.target/i386/switch-exp-transform-1.c
- gcc/tree-switch-conversion.cc 19 additions, 65 deletionsgcc/tree-switch-conversion.cc
- gcc/tree-switch-conversion.h 2 additions, 4 deletionsgcc/tree-switch-conversion.h
Loading
Please register or sign in to comment