Richard Earnshaw (rearnsha) <[email protected]> requested changes to the code:


> +++ gcc/config/arm/arm.md
> @@ -12858,1 +12856,3 @@
> -  "TARGET_SOFT_FLOAT && arm_arch_thumb2"
> +   (match_operand:SF 1 "general_operand")
> +   (match_operand:SF 2 "general_operand")]
> +  "(TARGET_SOFT_FLOAT || TARGET_HARD_FLOAT) && arm_arch_thumb2"
```
#define TARGET_HARD_FLOAT       (TARGET_HARD_FLOAT_SUB          \
                                 && !TARGET_GENERAL_REGS_ONLY)
#define TARGET_SOFT_FLOAT       (!TARGET_HARD_FLOAT_SUB)
```

So this is just `!TARGET_GENERAL_REGS_ONLY`.  But I'm not really sure we want 
to reject that explicitly here since we can handle it via the soft-float code 
anyway.

> +++ gcc/config/arm/arm.md
> @@ -12864,0 +12917,4 @@
> +     rtx scratch = gen_reg_rtx (SImode);
> +     emit_move_insn (scratch, gen_lowpart (SImode, operands[2]));
> +     emit_insn (gen_insv_t2 (scratch, GEN_INT (31), GEN_INT (0),
> +             force_reg (SImode, gen_lowpart (SImode, operands[1]))));
I don't think we need to restrict this code to target_thumb2.  here are some 
ideas:
For Arm pre t2:  
- If the sign is known, use BIC or ORR to set or clear the sign bit directly 
(this applies even when we have insv_t2).
- if the sign is variable, 
```
   AND tmp, sign, #0x80000000
   BIC target, op1, #0x80000000
   ORR target, target, tmp
```
(There are other sequences that avoid the need for a temporary, but clobber the 
condition codes, one is:
```
   CMP sign, #0x80000000
   ADC target, op1, op1
   MOV target, target, RRX
``` 
- For Thumb1
```
   LSLS    tmp, sign, #1      // C = signbit(sign)
   ADCS    a, a, a            // A = 2*A + C, losing its own sign bit
   MOVS    tmp2, #1
   RORS    a, tmp2            // Rotates the sign bit to the correct place
```
The first two instructions would need a specific pattern in the MD file since 
we depend on the carry-out of the first instruction propagating to the carry-in 
of the second.  Otherwise, this is just simple operations that we already have. 
 If the compiler already has 1 in a temporary, then that instruction will 
likely get optimized away; or hoisted out of a loop.  We'd also need to copy 
'a' from op1 first, since we can't just modify it directly and we can't assume 
it can be copied directly to target as that might overlap sign.

All that being said, we shouldn't generally re-use registers in this way, it's 
better to generate new temporaries for each intermediate result and let the 
register allocator and other optimizers clean that up.

A final note is that for soft-float, both sf and df need essentially the same 
code, so we should put all this into a helper pattern; the mode dependent parts 
can then call it (and for df-mode copy the remaining bits).


--
https://forge.sourceware.org/gcc/gcc/pulls/262#issuecomment-8373

Reply via email to