Skip to content

Commit c5df248

Browse files
Use BIT_FIELD_REF inside fold_single_bit_test
Instead of depending on combine to do the extraction, Let's create a tree which will expand directly into the extraction. This improves code generation on some targets. gcc/ChangeLog: * expr.cc (fold_single_bit_test): Use BIT_FIELD_REF instead of shift/and.
1 parent 5c68c27 commit c5df248

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

gcc/expr.cc

+10-11
Original file line numberDiff line numberDiff line change
@@ -12957,22 +12957,21 @@ fold_single_bit_test (location_t loc, enum tree_code code,
1295712957
intermediate_type = ops_unsigned ? unsigned_type : signed_type;
1295812958
inner = fold_convert_loc (loc, intermediate_type, inner);
1295912959

12960-
if (bitnum != 0)
12961-
inner = build2 (RSHIFT_EXPR, intermediate_type,
12962-
inner, size_int (bitnum));
12960+
tree bftype = build_nonstandard_integer_type (1, 1);
12961+
int bitpos = bitnum;
1296312962

12964-
one = build_int_cst (intermediate_type, 1);
12963+
if (BYTES_BIG_ENDIAN)
12964+
bitpos = GET_MODE_BITSIZE (operand_mode) - 1 - bitpos;
1296512965

12966-
if (code == EQ_EXPR)
12967-
inner = fold_build2_loc (loc, BIT_XOR_EXPR, intermediate_type, inner, one);
12966+
inner = build3_loc (loc, BIT_FIELD_REF, bftype, inner,
12967+
bitsize_int (1), bitsize_int (bitpos));
1296812968

12969-
/* Put the AND last so it can combine with more things. */
12970-
inner = build2 (BIT_AND_EXPR, intermediate_type, inner, one);
12969+
one = build_int_cst (bftype, 1);
1297112970

12972-
/* Make sure to return the proper type. */
12973-
inner = fold_convert_loc (loc, result_type, inner);
12971+
if (code == EQ_EXPR)
12972+
inner = fold_build2_loc (loc, BIT_XOR_EXPR, bftype, inner, one);
1297412973

12975-
return inner;
12974+
return fold_convert_loc (loc, result_type, inner);
1297612975
}
1297712976

1297812977
/* Generate code to calculate OPS, and exploded expression

0 commit comments

Comments
 (0)