https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114044

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Smaller testcase:
void
foo (void)
{
  unsigned _BitInt(256) a = 3;
  __builtin_clzg (a);
}

The thing is that in this testcase bitint lowering doesn't even know it should
do anything.
The whole behavior of the pass is keyed on there being any SSA_NAMEs for
middle/large/huge BITINT_TYPE with some extra exceptions (it looks at virtual
SSA_NAMEs to see if there isn't a memory store of a middle+ _BitInt INTEGER_CST
and for scalar floating point SSA_NAMEs if they aren't computed from conversion
from middle+ _BitInt INTEGER_CSTs), and even if the pass for some other reason
triggers in the function,
it will not look at statements which don't have any large+ _BitInt SSA_NAMEs,
or are large+ _BitInt INTEGER_CST store or FLOAT_EXPR from large+ _BitInt
INTEGER_CST or the overflow ifns with _Complex large+ _BitInt result.
We really don't want to lower those ifns like
.CLZ/.CTZ/.CLRSB/.POPCOUNT/.PARITY/.FFS
with INTEGER_CST operands, or after all even say .ADD_OVERFLOW (0, 1) where
just operands are large/huge _BitInt but say _Complex int result, those are all
expected to be folded instead.
Now, if s/^void/int;s/__builtin/return &/' above, we fold it in
gimple_fold_stmt_to_constant_1:
#0  wi::clz (x=...) at ../../gcc/wide-int.cc:2164
#1  0x00000000008a9d9b in fold_const_call_ss (result=0x7fffffffc4e0,
fn=CFN_CLZ, arg=..., precision=32, arg_type=<bitint_type 0x7fffea2db5e8>) at
../../gcc/fold-const-call.cc:1029
#2  0x00000000008aa9a5 in fold_const_call_1 (fn=CFN_CLZ, type=<integer_type
0x7fffea14c5e8 int>, arg=<integer_cst 0x7fffea2e5c18>) at
../../gcc/fold-const-call.cc:1254
#3  0x00000000008ab4d6 in fold_const_call (fn=CFN_CLZ, type=<integer_type
0x7fffea14c5e8 int>, arg=<integer_cst 0x7fffea2e5c18>) at
../../gcc/fold-const-call.cc:1385
#4  0x000000000189d6e0 in gimple_resimplify1 (seq=0x0, res_op=0x7fffffffc980,
valueize=0xf42f7d <valueize_op_1(tree)>) at
../../gcc/gimple-match-exports.cc:925
#5  0x000000000189b419 in gimple_match_op::resimplify (this=0x7fffffffc980,
seq=0x0, valueize=0xf42f7d <valueize_op_1(tree)>) at
../../gcc/gimple-match-exports.cc:111
#6  0x000000000189d5b3 in gimple_simplify (stmt=<gimple_call 0x7fffea13aea0>,
res_op=0x7fffffffc980, seq=0x0, valueize=0xf42f7d <valueize_op_1(tree)>, 
    top_valueize=0xf42f41 <valueize_op(tree)>) at
../../gcc/gimple-match-exports.cc:898
#7  0x000000000090986a in gimple_fold_stmt_to_constant_1 (stmt=<gimple_call
0x7fffea13aea0>, valueize=0xf42f41 <valueize_op(tree)>, gvalueize=0xf42f7d
<valueize_op_1(tree)>)
    at ../../gcc/gimple-fold.cc:7551
#8  0x0000000000f4308a in ccp_fold (stmt=<gimple_call 0x7fffea13aea0>) at
../../gcc/tree-ssa-ccp.cc:1290
#9  0x0000000000f48d1b in evaluate_stmt (stmt=<gimple_call 0x7fffea13aea0>) at
../../gcc/tree-ssa-ccp.cc:2228
or with extra -fno-tree-ccp in:
#0  wi::clz (x=...) at ../../gcc/wide-int.cc:2164
#1  0x00000000008a9d9b in fold_const_call_ss (result=0x7fffffffceb0,
fn=CFN_CLZ, arg=..., precision=32, arg_type=<bitint_type 0x7fffea2db5e8>) at
../../gcc/fold-const-call.cc:1029
#2  0x00000000008aa9a5 in fold_const_call_1 (fn=CFN_CLZ, type=<integer_type
0x7fffea14c5e8 int>, arg=<integer_cst 0x7fffea2e5c18>) at
../../gcc/fold-const-call.cc:1254
#3  0x00000000008ab4d6 in fold_const_call (fn=CFN_CLZ, type=<integer_type
0x7fffea14c5e8 int>, arg=<integer_cst 0x7fffea2e5c18>) at
../../gcc/fold-const-call.cc:1385
#4  0x000000000189d6e0 in gimple_resimplify1 (seq=0x7fffffffd278,
res_op=0x7fffffffd200, valueize=0xf811c3 <fwprop_ssa_val(tree)>) at
../../gcc/gimple-match-exports.cc:925
#5  0x000000000189b419 in gimple_match_op::resimplify (this=0x7fffffffd200,
seq=0x7fffffffd278, valueize=0xf811c3 <fwprop_ssa_val(tree)>) at
../../gcc/gimple-match-exports.cc:111
#6  0x000000000189d5b3 in gimple_simplify (stmt=<gimple_call 0x7fffea13ae10>,
res_op=0x7fffffffd200, seq=0x7fffffffd278, valueize=0xf811c3
<fwprop_ssa_val(tree)>, 
    top_valueize=0xf811c3 <fwprop_ssa_val(tree)>) at
../../gcc/gimple-match-exports.cc:898
#7  0x00000000009060dd in fold_stmt_1 (gsi=0x7fffffffd630, inplace=false,
valueize=0xf811c3 <fwprop_ssa_val(tree)>) at ../../gcc/gimple-fold.cc:6359
#8  0x0000000000906833 in fold_stmt (gsi=0x7fffffffd630, valueize=0xf811c3
<fwprop_ssa_val(tree)>) at ../../gcc/gimple-fold.cc:6525
or with extra -fno-tree-ccp -fno-tree-forwprop in:
#0  wi::clz (x=...) at ../../gcc/wide-int.cc:2164
#1  0x00000000008a9d9b in fold_const_call_ss (result=0x7fffffffcd50,
fn=CFN_CLZ, arg=..., precision=32, arg_type=<bitint_type 0x7fffea2db5e8>) at
../../gcc/fold-const-call.cc:1029
#2  0x00000000008aa9a5 in fold_const_call_1 (fn=CFN_CLZ, type=<integer_type
0x7fffea14c5e8 int>, arg=<integer_cst 0x7fffea2e5c18>) at
../../gcc/fold-const-call.cc:1254
#3  0x00000000008ab4d6 in fold_const_call (fn=CFN_CLZ, type=<integer_type
0x7fffea14c5e8 int>, arg=<integer_cst 0x7fffea2e5c18>) at
../../gcc/fold-const-call.cc:1385
#4  0x000000000189d6e0 in gimple_resimplify1 (seq=0x0, res_op=0x7fffffffd1f0,
valueize=0x906784 <no_follow_ssa_edges(tree_node*)>) at
../../gcc/gimple-match-exports.cc:925
#5  0x000000000189b419 in gimple_match_op::resimplify (this=0x7fffffffd1f0,
seq=0x0, valueize=0x906784 <no_follow_ssa_edges(tree_node*)>) at
../../gcc/gimple-match-exports.cc:111
#6  0x000000000189d5b3 in gimple_simplify (stmt=<gimple_call 0x7fffea13ae10>,
res_op=0x7fffffffd1f0, seq=0x0, valueize=0x906784
<no_follow_ssa_edges(tree_node*)>, 
    top_valueize=0x106aeba <rpo_vn_valueize(tree_node*)>) at
../../gcc/gimple-match-exports.cc:898
#7  0x000000000090986a in gimple_fold_stmt_to_constant_1 (stmt=<gimple_call
0x7fffea13ae10>, valueize=0x106aeba <rpo_vn_valueize(tree_node*)>, 
    gvalueize=0x906784 <no_follow_ssa_edges(tree_node*)>) at
../../gcc/gimple-fold.cc:7551
#8  0x000000000106502d in visit_stmt (stmt=<gimple_call 0x7fffea13ae10>,
backedges_varying_p=false) at ../../gcc/tree-ssa-sccvn.cc:6419
etc.
But somehow none of that triggers if the internal fn doesn't have lhs, we just
rely on DCE and DCE can be disabled.
Dunno, shall we just ignore those during expansion if they don't have lhs?

Reply via email to