From 49b82a54d00f43b17c50366d3723c7553f808680 Mon Sep 17 00:00:00 2001 From: jasonwucj Date: Wed, 25 Apr 2018 12:32:19 +0000 Subject: [PATCH] [NDS32] Fix bug in bit-instruction checking functions. gcc/ * config/nds32/nds32-predicates.c (nds32_can_use_bclr_p): Mask with GET_MODE_MASK before any checking. (nds32_can_use_bset_p): Likewise. (nds32_can_use_btgl_p): Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@259647 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 7 +++++++ gcc/config/nds32/nds32-predicates.c | 9 ++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a0adc88433e..6ea0aaa7eea 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,12 @@ 2018-04-25 Chung-Ju Wu + * config/nds32/nds32-predicates.c (nds32_can_use_bclr_p): Mask with + GET_MODE_MASK before any checking. + (nds32_can_use_bset_p): Likewise. + (nds32_can_use_btgl_p): Likewise. + +2018-04-25 Chung-Ju Wu + * config/nds32/nds32-doubleword.md: New define_split pattern for illegal register number. diff --git a/gcc/config/nds32/nds32-predicates.c b/gcc/config/nds32/nds32-predicates.c index 5e01430c8e3..a670623bf9a 100644 --- a/gcc/config/nds32/nds32-predicates.c +++ b/gcc/config/nds32/nds32-predicates.c @@ -360,12 +360,13 @@ int nds32_can_use_bclr_p (int ival) { int one_bit_count; + unsigned HOST_WIDE_INT mask = GET_MODE_MASK (SImode); /* Calculate the number of 1-bit of (~ival), if there is only one 1-bit, it means the original ival has only one 0-bit, So it is ok to perform 'bclr' operation. */ - one_bit_count = popcount_hwi ((unsigned HOST_WIDE_INT) (~ival)); + one_bit_count = popcount_hwi ((unsigned HOST_WIDE_INT) (~ival) & mask); /* 'bclr' is a performance extension instruction. */ return (TARGET_EXT_PERF && (one_bit_count == 1)); @@ -376,11 +377,12 @@ int nds32_can_use_bset_p (int ival) { int one_bit_count; + unsigned HOST_WIDE_INT mask = GET_MODE_MASK (SImode); /* Caculate the number of 1-bit of ival, if there is only one 1-bit, it is ok to perform 'bset' operation. */ - one_bit_count = popcount_hwi ((unsigned HOST_WIDE_INT) (ival)); + one_bit_count = popcount_hwi ((unsigned HOST_WIDE_INT) (ival) & mask); /* 'bset' is a performance extension instruction. */ return (TARGET_EXT_PERF && (one_bit_count == 1)); @@ -391,11 +393,12 @@ int nds32_can_use_btgl_p (int ival) { int one_bit_count; + unsigned HOST_WIDE_INT mask = GET_MODE_MASK (SImode); /* Caculate the number of 1-bit of ival, if there is only one 1-bit, it is ok to perform 'btgl' operation. */ - one_bit_count = popcount_hwi ((unsigned HOST_WIDE_INT) (ival)); + one_bit_count = popcount_hwi ((unsigned HOST_WIDE_INT) (ival) & mask); /* 'btgl' is a performance extension instruction. */ return (TARGET_EXT_PERF && (one_bit_count == 1)); -- 2.11.4.GIT