fold-const: Fix BIT_INSERT_EXPR folding for BYTES_BIG_ENDIAN [PR116997]
Fix constant folding of BIT_INSER_EXPR for BYTES_BIG_ENDIAN targets. gcc/ChangeLog: PR middle-end/116997 * fold-const.cc (fold_ternary_loc): Fix BIT_INSERT_EXPR constant folding for BYTES_BIG_ENDIAN targets. gcc/testsuite/ChangeLog: * gcc.dg/vect/pr116997.c: New test. Co-authored-by: Andrew Pinski <quic_apinski@quicinc.com>
This commit is contained in:
parent
ddd46d481a
commit
2e30e90a0c
2 changed files with 20 additions and 0 deletions
|
@ -13712,6 +13712,8 @@ fold_ternary_loc (location_t loc, enum tree_code code, tree type,
|
|||
{
|
||||
unsigned HOST_WIDE_INT bitpos = tree_to_uhwi (op2);
|
||||
unsigned bitsize = TYPE_PRECISION (TREE_TYPE (arg1));
|
||||
if (BYTES_BIG_ENDIAN)
|
||||
bitpos = TYPE_PRECISION (type) - bitpos - bitsize;
|
||||
wide_int tem = (wi::to_wide (arg0)
|
||||
& wi::shifted_mask (bitpos, bitsize, true,
|
||||
TYPE_PRECISION (type)));
|
||||
|
|
18
gcc/testsuite/gcc.dg/vect/pr116997.c
Normal file
18
gcc/testsuite/gcc.dg/vect/pr116997.c
Normal file
|
@ -0,0 +1,18 @@
|
|||
/* PR 116997. */
|
||||
struct S0
|
||||
{
|
||||
unsigned f0;
|
||||
signed f2 : 11;
|
||||
signed : 6;
|
||||
} GlobS, *Ptr = &GlobS;
|
||||
|
||||
const struct S0 Initializer = {7, 3};
|
||||
|
||||
int main (void)
|
||||
{
|
||||
for (unsigned i = 0; i <= 2; i++)
|
||||
*Ptr = Initializer;
|
||||
if (GlobS.f2 != 3)
|
||||
__builtin_abort ();
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Reference in a new issue