Skip to content
Snippets Groups Projects
Commit ffc389cb authored by Filip Kastl's avatar Filip Kastl
Browse files

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: default avatarFilip Kastl <fkastl@suse.cz>
parent 842fbfa1
No related branches found
No related tags found
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment