This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: The subreg question
Ling-hua Tseng wrote:
(Does (high:SI ...) have the semantic of clearing LSB 16-bit ? )
Storing an SImode value into an SImode reg will set the entire register,
unless you are using subreg/zero_extract/etc on the destination. So
yes, this will clear the low order bits, where the number of low order
bits cleared is machine dependent.
[(set (high:SI (match_operand:SI 0 "register_operand" "=r"))
(high:SI (match_operand:SI 1 "immediate_operand" "i")))
You can't use HIGH in a destination. Do something like this:
(set (op 0)
(ior:SI (high:SI (op 1)
(zero_extend:SI (subreg:HI (op 0)))))
3. set LSB 16-bit and clear MSB 16-bit to zero
[(set (match_operand:SI 0 "register_operand" "=r")
(match_operand:HI 1 "immediate_operand" "i"))]
You can't mix modes like this. The source and destination have to have
the same mode. Also, immediates don't have modes, so trying to take an
HImode immediate makes no sense. This should just be something like
(set (match_op:SI 0 ... "=r")
(match_op:SI 1 ... "J"))
where 'J' is defined via CONST_OK_FOR_LETTER_P to be a constant that can
fit in 16 bits (zero extended).
4. set LSB 16-bit and unchange/keep LSB 16-bit
[(set (strict_lowpart (subreg:HI (match_operand:SI 0
"register_operand" "=r") 0))
(match_operand:HI "immediate_operand" "i"))]
(Would it better than use (lo_sum:SI ...) ? )
Using strict_low_part like this is OK.
Using lo_sum is probably not useful here, since you aren't doing an
addition.
lo_sum is primarily useful when setting an entire register with two
operations, one of which is a high. E.g. if you have
(set (op 0) (high: (op 1)))
(set (op 0) (lo_sum (op 0) (op 1)))
then the RTL optimizatize will know that this is equivalent to
(set (op 0) (op 1))
If you mix high with strict_low_part, the optimizer will not be able to
do anything with this.
Even though your instructions technically isn't an add, use of lo_sum is
probably safe here. The optimizer doesn't do anything else with a
lo_sum other than simplify it with high, and since high clears the low
bits, conceptually an addition is safe here as it can't overflow the low
bits if you are adding with zero.
--
Jim Wilson, GNU Tools Support, http://www.SpecifixInc.com