Add TARGET_HARD_FLOAT condition for float instructions template.
Disable instructions that do not exist on la32r.
gcc/ChangeLog:
* config/loongarch/larchintrin.h (__movgr2fcsr): Disable on soft float.
(__crc_w_w_w): Disable on la32.
(__crc_w_d_w): Likewise.
(__crcc_w_w_w): Likewise.
(__iocsrrd_w): Likewise.
(__iocsrrd_d): Likewise.
(__iocsrwr_w): Likewise.
* config/loongarch/loongarch.cc (loongarch_legitimize_address): Disable
(plus (plus (mult (a) (mem_shadd_constant)) (fp)) (C)) on la32r.
(loongarch_output_equal_conditional_branch): Disable beqz/bnez on la32r.
* config/loongarch/loongarch.md (!TARGET_32BIT_R): Disable rotatert.
(*and<mode>3): Delete and/andi, rename to *and<mode>3_extend.
(*and<mode>3_extend): New.
(zero_extend<SHORT:mode><GPR:mode>2_la32r): New.
(extend<SHORT:mode><GPR:mode>2_la32r): New.
(extendqihi2_la32r): New.
* config/loongarch/predicates.md: Disable low_bitmask_operand and
ins_zero_bitmask_operand on la32r.
* config/loongarch/sync.md: Change beqz to beq and change orn to nor +
or.
include/ChangeLog:
* longlong.h (count_leading_zeros): Delete on la32r.
(count_trailing_zeros): Likewise.
(COUNT_LEADING_ZEROS_0): Likewise.
---
gcc/config/loongarch/larchintrin.h | 18 +--
gcc/config/loongarch/loongarch.cc | 11 +-
gcc/config/loongarch/loongarch.md | 173 +++++++++++++++++------------
gcc/config/loongarch/predicates.md | 4 +-
gcc/config/loongarch/sync.md | 38 ++++---
include/longlong.h | 6 +-
6 files changed, 147 insertions(+), 103 deletions(-)
diff --git a/gcc/config/loongarch/larchintrin.h
b/gcc/config/loongarch/larchintrin.h
index 299b1c6a49d..e0fe1df8c9c 100644
--- a/gcc/config/loongarch/larchintrin.h
+++ b/gcc/config/loongarch/larchintrin.h
@@ -80,6 +80,7 @@ __rdtimel_w (void)
return __rdtime;
}
+#ifdef __loongarch_hard_float
/* Assembly instruction format: rj, fcsr. */
/* Data types in instruction templates: USI, UQI. */
#define __movfcsr2gr(/*ui5*/ _1) __builtin_loongarch_movfcsr2gr ((_1));
@@ -88,13 +89,14 @@ __rdtimel_w (void)
/* Data types in instruction templates: VOID, UQI, USI. */
#define __movgr2fcsr(/*ui5*/ _1, _2) \
__builtin_loongarch_movgr2fcsr ((_1), _2);
+#endif
-#if defined __loongarch64
+#if __loongarch_grlen == 64
/* Assembly instruction format: ui5, rj, si12. */
/* Data types in instruction templates: VOID, USI, UDI, SI. */
#define __cacop_d(/*ui5*/ _1, /*unsigned long int*/ _2, /*si12*/ _3) \
__builtin_loongarch_cacop_d ((_1), (_2), (_3))
-#elif defined __loongarch32
+#elif __loongarch_grlen == 32
#define __cacop_w(/*ui5*/ _1, /*unsigned long int*/ _2, /*si12*/ _3) \
__builtin_loongarch_cacop_w ((_1), (_2), (_3))
#else
@@ -130,30 +132,31 @@ __asrtgt_d (long int _1, long int _2)
}
#endif
-#if defined __loongarch64
+#if __loongarch_grlen == 64
/* Assembly instruction format: rd, rj, ui5. */
/* Data types in instruction templates: DI, DI, UQI. */
#define __lddir_d(/*long int*/ _1, /*ui5*/ _2) \
__builtin_loongarch_lddir_d ((_1), (_2))
-#elif defined __loongarch32
+#elif __loongarch_grlen == 32
#define __lddir_w(/*long int*/ _1, /*ui5*/ _2) \
__builtin_loongarch_lddir_w ((_1), (_2))
#else
#error "Unsupported ABI."
#endif
-#if defined __loongarch64
+#if __loongarch_grlen == 64
/* Assembly instruction format: rj, ui5. */
/* Data types in instruction templates: VOID, DI, UQI. */
#define __ldpte_d(/*long int*/ _1, /*ui5*/ _2) \
__builtin_loongarch_ldpte_d ((_1), (_2))
-#elif defined __loongarch32
+#elif __loongarch_grlen == 32
#define __ldpte_w(/*long int*/ _1, /*ui5*/ _2) \
__builtin_loongarch_ldpte_w ((_1), (_2))
#else
#error "Unsupported ABI."
#endif
+#ifdef __loongarch64
/* Assembly instruction format: rd, rj, rk. */
/* Data types in instruction templates: SI, QI, SI. */
extern __inline int
@@ -181,7 +184,6 @@ __crc_w_w_w (int _1, int _2)
return __builtin_loongarch_crc_w_w_w (_1, _2);
}
-#ifdef __loongarch64
/* Assembly instruction format: rd, rj, rk. */
/* Data types in instruction templates: SI, DI, SI. */
extern __inline int
@@ -190,7 +192,6 @@ __crc_w_d_w (long int _1, int _2)
{
return __builtin_loongarch_crc_w_d_w (_1, _2);
}
-#endif
/* Assembly instruction format: rd, rj, rk. */
/* Data types in instruction templates: SI, QI, SI. */
@@ -219,7 +220,6 @@ __crcc_w_w_w (int _1, int _2)
return __builtin_loongarch_crcc_w_w_w (_1, _2);
}
-#ifdef __loongarch64
/* Assembly instruction format: rd, rj, rk. */
/* Data types in instruction templates: SI, DI, SI. */
extern __inline int
diff --git a/gcc/config/loongarch/loongarch.cc
b/gcc/config/loongarch/loongarch.cc
index c31805db95d..f54cd4cc054 100644
--- a/gcc/config/loongarch/loongarch.cc
+++ b/gcc/config/loongarch/loongarch.cc
@@ -3416,7 +3416,9 @@ loongarch_legitimize_address (rtx x, rtx oldx
ATTRIBUTE_UNUSED,
if (offset != 0)
{
/* Handle (plus (plus (mult (a) (mem_shadd_constant)) (fp)) (C)) case.
*/
- if (GET_CODE (base) == PLUS && mem_shadd_or_shadd_rtx_p (XEXP (base, 0))
+ if ((TARGET_64BIT || TARGET_32BIT_S)
+ && GET_CODE (base) == PLUS
+ && mem_shadd_or_shadd_rtx_p (XEXP (base, 0))
&& IMM12_OPERAND (offset))
{
rtx index = XEXP (base, 0);
@@ -7677,7 +7679,8 @@ loongarch_output_equal_conditional_branch (rtx_insn
*insn, rtx *operands,
bool inverted_p)
{
const char *branch[2];
- if (operands[3] == const0_rtx)
+ if ((TARGET_64BIT || TARGET_32BIT_S)
+ && operands[3] == const0_rtx)
{
branch[!inverted_p] = LARCH_BRANCH ("b%C1z", "%2,%0");
branch[inverted_p] = LARCH_BRANCH ("b%N1z", "%2,%0");
@@ -8345,11 +8348,11 @@ loongarch_trampoline_init (rtx m_tramp, tree fndecl,
rtx chain_value)
/* Build up the code in TRAMPOLINE. */
i = 0;
- /*pcaddi $static_chain,0
+ /*pcaddu12i $static_chain,0
ld.[dw] $tmp,$static_chain,target_function_offset
ld.[dw] $static_chain,$static_chain,static_chain_offset
jirl $r0,$tmp,0 */
- trampoline[i++] = OP (0x18000000 | (STATIC_CHAIN_REGNUM - GP_REG_FIRST));
+ trampoline[i++] = OP (0x1c000000 | (STATIC_CHAIN_REGNUM - GP_REG_FIRST));
trampoline[i++] = OP ((ptr_mode == DImode ? 0x28c00000 : 0x28800000)
| 19 /* $t7 */
| ((STATIC_CHAIN_REGNUM - GP_REG_FIRST) << 5)
diff --git a/gcc/config/loongarch/loongarch.md
b/gcc/config/loongarch/loongarch.md
index 1127f198200..f3bcea2cb4e 100644
--- a/gcc/config/loongarch/loongarch.md
+++ b/gcc/config/loongarch/loongarch.md
@@ -639,7 +639,7 @@ (define_int_attr bytepick_imm [(8 "1")
;; so the redundant sign extension can be removed if the output is used as
;; an input of a bitwise operation. Note plus, rotl, and div are handled
;; separately.
-(define_code_iterator shift_w [any_shift rotatert])
+(define_code_iterator shift_w [any_shift (rotatert "!TARGET_32BIT_R")])
(define_code_iterator arith_w [minus mult])
(define_expand "<optab><mode>3"
@@ -1203,7 +1203,7 @@ (define_insn "fnms<mode>4"
(neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
(match_operand:ANYF 2 "register_operand" "f")
(neg:ANYF (match_operand:ANYF 3 "register_operand" "f"))))]
- "!HONOR_SIGNED_ZEROS (<MODE>mode)"
+ "TARGET_HARD_FLOAT && !HONOR_SIGNED_ZEROS (<MODE>mode)"
"fnmadd.<fmt>\t%0,%1,%2,%3"
[(set_attr "type" "fmadd")
(set_attr "mode" "<UNITMODE>")])
@@ -1385,7 +1385,7 @@ (define_insn "ldexp<mode>3"
(unspec:ANYF [(match_operand:ANYF 1 "register_operand" "f")
(match_operand:<IMODE> 2 "register_operand" "f")]
UNSPEC_FSCALEB))]
- "TARGET_HARD_FLOAT"
+ "TARGET_64BIT"
"fscaleb.<fmt>\t%0,%1,%2"
[(set_attr "type" "fscaleb")
(set_attr "mode" "<UNITMODE>")])
@@ -1401,7 +1401,7 @@ (define_insn "logb_non_negative<mode>2"
[(set (match_operand:ANYF 0 "register_operand" "=f")
(unspec:ANYF [(match_operand:ANYF 1 "register_operand" "f")]
UNSPEC_FLOGB))]
- "TARGET_HARD_FLOAT"
+ "TARGET_64BIT"
"flogb.<fmt>\t%0,%1"
[(set_attr "type" "flogb")
(set_attr "mode" "<UNITMODE>")])
@@ -1410,7 +1410,7 @@ (define_expand "logb<mode>2"
[(set (match_operand:ANYF 0 "register_operand")
(unspec:ANYF [(abs:ANYF (match_operand:ANYF 1 "register_operand"))]
UNSPEC_FLOGB))]
- "TARGET_HARD_FLOAT"
+ "TARGET_64BIT"
{
rtx tmp = gen_reg_rtx (<MODE>mode);
@@ -1430,7 +1430,7 @@ (define_expand "logb<mode>2"
(define_insn "clz<mode>2"
[(set (match_operand:GPR 0 "register_operand" "=r")
(clz:GPR (match_operand:GPR 1 "register_operand" "r")))]
- ""
+ "TARGET_64BIT || TARGET_32BIT_S"
"clz.<d>\t%0,%1"
[(set_attr "type" "clz")
(set_attr "mode" "<MODE>")])
@@ -1446,7 +1446,7 @@ (define_insn "clz<mode>2"
(define_insn "ctz<mode>2"
[(set (match_operand:GPR 0 "register_operand" "=r")
(ctz:GPR (match_operand:GPR 1 "register_operand" "r")))]
- ""
+ "TARGET_64BIT || TARGET_32BIT_S"
"ctz.<d>\t%0,%1"
[(set_attr "type" "clz")
(set_attr "mode" "<MODE>")])
@@ -1562,28 +1562,26 @@ (define_insn "neg<mode>2"
(define_insn "*<optab><mode>3"
[(set (match_operand:GPR 0 "register_operand" "=r,r")
- (any_or:GPR (match_operand:GPR 1 "register_operand" "%r,r")
- (match_operand:GPR 2 "uns_arith_operand" "r,K")))]
+ (any_bitwise:GPR (match_operand:GPR 1 "register_operand" "%r,r")
+ (match_operand:GPR 2 "uns_arith_operand" "r,K")))]
""
"<insn>%i2\t%0,%1,%2"
[(set_attr "type" "logical")
(set_attr "mode" "<MODE>")])
-(define_insn "*and<mode>3"
- [(set (match_operand:GPR 0 "register_operand" "=r,r,r,r")
- (and:GPR (match_operand:GPR 1 "register_operand" "%r,r,r,0")
- (match_operand:GPR 2 "and_operand" "r,K,Yx,Yy")))]
- ""
+(define_insn "*and<mode>3_extend"
+ [(set (match_operand:GPR 0 "register_operand" "=r,r")
+ (and:GPR (match_operand:GPR 1 "register_operand" "%r,0")
+ (match_operand:GPR 2 "and_operand" "Yx,Yy")))]
+ "TARGET_64BIT || TARGET_32BIT_S"
"@
- and\t%0,%1,%2
- andi\t%0,%1,%2
* operands[2] = GEN_INT (INTVAL (operands[2]) \
& GET_MODE_MASK (<MODE>mode)); \
return \"bstrpick.<d>\t%0,%1,%M2\";
* operands[2] = GEN_INT (~INTVAL (operands[2]) \
& GET_MODE_MASK (<MODE>mode)); \
return \"bstrins.<d>\t%0,%.,%M2\";"
- [(set_attr "move_type" "logical,logical,pick_ins,pick_ins")
+ [(set_attr "move_type" "pick_ins,pick_ins")
(set_attr "mode" "<MODE>")])
(define_expand "<optab><mode>3"
@@ -1615,7 +1613,8 @@ (define_insn_and_split "*bstrins_<mode>_for_ior_mask"
(match_operand:GPR 2 "const_int_operand" "i"))
(and:GPR (match_operand:GPR 3 "register_operand" "r")
(match_operand:GPR 4 "const_int_operand" "i"))))]
- "loongarch_pre_reload_split ()
+ "(TARGET_64BIT || TARGET_32BIT_S )
+ && loongarch_pre_reload_split ()
&& loongarch_use_bstrins_for_ior_with_mask (<MODE>mode, operands)"
"#"
"&& true"
@@ -1684,7 +1683,7 @@ (define_peephole2
(match_operand:SI 3 "const_int_operand")
(const_int 0))
(match_dup 0))]
- "peep2_reg_dead_p (3, operands[0])"
+ "(TARGET_64BIT || TARGET_32BIT_S) && peep2_reg_dead_p (3, operands[0])"
[(const_int 0)]
{
int len = GET_MODE_BITSIZE (<MODE>mode) - INTVAL (operands[3]);
@@ -1745,7 +1744,7 @@ (define_insn "<optab>n<mode>3"
(neg_bitwise:X
(not:X (match_operand:X 2 "register_operand" "r"))
(match_operand:X 1 "register_operand" "r")))]
- ""
+ "TARGET_64BIT || TARGET_32BIT_S"
"<insn>n\t%0,%1,%2"
[(set_attr "type" "logical")
(set_attr "mode" "<MODE>")])
@@ -1844,7 +1843,7 @@ (define_insn "zero_extend<SHORT:mode><GPR:mode>2"
[(set (match_operand:GPR 0 "register_operand" "=r,r,r")
(zero_extend:GPR
(match_operand:SHORT 1 "nonimmediate_operand" "r,m,k")))]
- ""
+ "TARGET_64BIT || TARGET_32BIT_S"
"@
bstrpick.w\t%0,%1,<SHORT:7_or_15>,0
ld.<SHORT:size>u\t%0,%1
@@ -1852,6 +1851,15 @@ (define_insn "zero_extend<SHORT:mode><GPR:mode>2"
[(set_attr "move_type" "pick_ins,load,load")
(set_attr "mode" "<GPR:MODE>")])
+(define_insn "zero_extend<SHORT:mode><GPR:mode>2_la32r"
+ [(set (match_operand:GPR 0 "register_operand" "=r")
+ (zero_extend:GPR
+ (match_operand:SHORT 1 "nonimmediate_operand" "m")))]
+ "TARGET_32BIT_R"
+ "ld.<SHORT:size>u\t%0,%1"
+ [(set_attr "move_type" "load")
+ (set_attr "mode" "<GPR:MODE>")])
+
(define_insn "zero_extendqihi2"
[(set (match_operand:HI 0 "register_operand" "=r,r,r")
(zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "r,k,m")))]
@@ -1869,7 +1877,7 @@ (define_insn "*zero_extend<GPR:mode>_trunc<SHORT:mode>"
[(set (match_operand:GPR 0 "register_operand" "=r")
(zero_extend:GPR
(truncate:SHORT (match_operand:DI 1 "register_operand" "r"))))]
- "TARGET_64BIT"
+ "TARGET_64BIT || TARGET_32BIT_S"
"bstrpick.w\t%0,%1,<SHORT:7_or_15>,0"
[(set_attr "move_type" "pick_ins")
(set_attr "mode" "<GPR:MODE>")])
@@ -1878,7 +1886,7 @@ (define_insn "*zero_extendhi_truncqi"
[(set (match_operand:HI 0 "register_operand" "=r")
(zero_extend:HI
(truncate:QI (match_operand:DI 1 "register_operand" "r"))))]
- "TARGET_64BIT"
+ ""
"andi\t%0,%1,0xff"
[(set_attr "alu_type" "and")
(set_attr "mode" "HI")])
@@ -1908,7 +1916,7 @@ (define_insn "extend<SHORT:mode><GPR:mode>2"
[(set (match_operand:GPR 0 "register_operand" "=r,r,r")
(sign_extend:GPR
(match_operand:SHORT 1 "nonimmediate_operand" "r,m,k")))]
- ""
+ "TARGET_64BIT || TARGET_32BIT_S"
"@
ext.w.<SHORT:size>\t%0,%1
ld.<SHORT:size>\t%0,%1
@@ -1916,6 +1924,15 @@ (define_insn "extend<SHORT:mode><GPR:mode>2"
[(set_attr "move_type" "signext,load,load")
(set_attr "mode" "<GPR:MODE>")])
+(define_insn "extend<SHORT:mode><GPR:mode>2_la32r"
+ [(set (match_operand:GPR 0 "register_operand" "=r")
+ (sign_extend:GPR
+ (match_operand:SHORT 1 "nonimmediate_operand" "m")))]
+ "TARGET_32BIT_R"
+ "ld.<SHORT:size>\t%0,%1"
+ [(set_attr "move_type" "load")
+ (set_attr "mode" "<GPR:MODE>")])
+
(define_insn "extendqihi2"
[(set (match_operand:HI 0 "register_operand" "=r,r,r")
(sign_extend:HI
@@ -1928,6 +1945,15 @@ (define_insn "extendqihi2"
[(set_attr "move_type" "signext,load,load")
(set_attr "mode" "SI")])
+(define_insn "extendqihi2_la32r"
+ [(set (match_operand:HI 0 "register_operand" "=r")
+ (sign_extend:HI
+ (match_operand:QI 1 "nonimmediate_operand" "m")))]
+ ""
+ "ld.b\t%0,%1"
+ [(set_attr "move_type" "load")
+ (set_attr "mode" "SI")])
+
(define_insn "extendsfdf2"
[(set (match_operand:DF 0 "register_operand" "=f")
(float_extend:DF (match_operand:SF 1 "register_operand" "f")))]
@@ -2168,11 +2194,11 @@ (define_expand "fixuns_truncsfdi2"
;; ....................
(define_expand "extzv<mode>"
- [(set (match_operand:X 0 "register_operand")
- (zero_extract:X (match_operand:X 1 "register_operand")
+ [(set (match_operand:GPR 0 "register_operand")
+ (zero_extract:GPR (match_operand:GPR 1 "register_operand")
(match_operand 2 "const_int_operand")
(match_operand 3 "const_int_operand")))]
- ""
+ "TARGET_64BIT || TARGET_32BIT_S"
{
if (!loongarch_use_ins_ext_p (operands[1], INTVAL (operands[2]),
INTVAL (operands[3])))
@@ -2180,12 +2206,13 @@ (define_expand "extzv<mode>"
})
(define_insn "*extzv<mode>"
- [(set (match_operand:X 0 "register_operand" "=r")
- (zero_extract:X (match_operand:X 1 "register_operand" "r")
- (match_operand 2 "const_int_operand" "")
- (match_operand 3 "const_int_operand" "")))]
- "loongarch_use_ins_ext_p (operands[1], INTVAL (operands[2]),
- INTVAL (operands[3]))"
+ [(set (match_operand:GPR 0 "register_operand" "=r")
+ (zero_extract:GPR (match_operand:GPR 1 "register_operand" "r")
+ (match_operand 2 "const_int_operand" "")
+ (match_operand 3 "const_int_operand" "")))]
+ "(TARGET_64BIT || TARGET_32BIT_S)
+ && loongarch_use_ins_ext_p (operands[1], INTVAL (operands[2]),
+ INTVAL (operands[3]))"
{
operands[2] = GEN_INT (INTVAL (operands[2]) + INTVAL (operands[3]) - 1);
return "bstrpick.<d>\t%0,%1,%2,%3";
@@ -2198,7 +2225,7 @@ (define_expand "insv<mode>"
(match_operand 1 "const_int_operand")
(match_operand 2 "const_int_operand"))
(match_operand:GPR 3 "reg_or_0_operand"))]
- ""
+ "TARGET_64BIT || TARGET_32BIT_S"
{
if (!loongarch_use_ins_ext_p (operands[0], INTVAL (operands[1]),
INTVAL (operands[2])))
@@ -2210,8 +2237,9 @@ (define_insn "*insv<mode>"
(match_operand:SI 1 "const_int_operand" "")
(match_operand:SI 2 "const_int_operand" ""))
(match_operand:GPR 3 "reg_or_0_operand" "rJ"))]
- "loongarch_use_ins_ext_p (operands[0], INTVAL (operands[1]),
- INTVAL (operands[2]))"
+ "(TARGET_64BIT || TARGET_32BIT_S)
+ && loongarch_use_ins_ext_p (operands[0], INTVAL (operands[1]),
+ INTVAL (operands[2]))"
{
operands[1] = GEN_INT (INTVAL (operands[1]) + INTVAL (operands[2]) - 1);
return "bstrins.<d>\t%0,%z3,%1,%2";
@@ -2332,7 +2360,7 @@ (define_insn "la_pcrel64_two_parts"
(unspec:DI [(match_operand:DI 2 "") (pc)] UNSPEC_LA_PCREL_64_PART1))
(set (match_operand:DI 1 "register_operand" "=r")
(unspec:DI [(match_dup 2) (pc)] UNSPEC_LA_PCREL_64_PART2))]
- "TARGET_ABI_LP64 && la_opt_explicit_relocs != EXPLICIT_RELOCS_NONE"
+ "TARGET_64BIT && la_opt_explicit_relocs != EXPLICIT_RELOCS_NONE"
{
return "pcalau12i\t%0,%r2\n\t"
"addi.d\t%1,$r0,%L2\n\t"
@@ -2452,7 +2480,7 @@ (define_insn "*movqi_internal"
(define_expand "movsf"
[(set (match_operand:SF 0 "")
(match_operand:SF 1 ""))]
- ""
+ "TARGET_HARD_FLOAT"
{
if (loongarch_legitimize_move (SFmode, operands[0], operands[1]))
DONE;
@@ -2483,7 +2511,7 @@ (define_insn "*movsf_softfloat"
(define_expand "movdf"
[(set (match_operand:DF 0 "")
(match_operand:DF 1 ""))]
- ""
+ "TARGET_DOUBLE_FLOAT"
{
if (loongarch_legitimize_move (DFmode, operands[0], operands[1]))
DONE;
@@ -2623,8 +2651,9 @@ (define_insn "*sel<code><GPR:mode>_using_<X:mode>"
(const_int 0))
(match_operand:GPR 2 "reg_or_0_operand" "r,J")
(match_operand:GPR 3 "reg_or_0_operand" "J,r")))]
- "register_operand (operands[2], <GPR:MODE>mode)
- != register_operand (operands[3], <GPR:MODE>mode)"
+ "(TARGET_64BIT || TARGET_32BIT_S)
+ && register_operand (operands[2], <GPR:MODE>mode)
+ != register_operand (operands[3], <GPR:MODE>mode)"
"@
<sel>\t%0,%2,%1
<selinv>\t%0,%3,%1"
@@ -2686,7 +2715,7 @@ (define_expand "mov<mode>cc"
(if_then_else:GPR (match_operator 1 "comparison_operator"
[(match_operand:GPR 2 "reg_or_0_operand")
(match_operand:GPR 3 "reg_or_0_operand")])))]
- "TARGET_COND_MOVE_INT"
+ "(TARGET_64BIT || TARGET_32BIT_S) && TARGET_COND_MOVE_INT"
{
if (!INTEGRAL_MODE_P (GET_MODE (XEXP (operands[1], 0))))
FAIL;
@@ -2791,7 +2820,7 @@ (define_insn "@pcalau12i<mode>"
[(set (match_operand:P 0 "register_operand" "=j")
(unspec:P [(match_operand:P 1 "symbolic_operand" "")]
UNSPEC_PCALAU12I))]
- ""
+ "TARGET_64BIT || TARGET_32BIT_S"
"pcalau12i\t%0,%%pc_hi20(%1)"
[(set_attr "type" "move")])
@@ -2801,7 +2830,7 @@ (define_insn "@pcalau12i_gr<mode>"
[(set (match_operand:P 0 "register_operand" "=r")
(unspec:P [(match_operand:P 1 "symbolic_operand" "")]
UNSPEC_PCALAU12I_GR))]
- ""
+ "TARGET_64BIT || TARGET_32BIT_S"
"pcalau12i\t%0,%%pc_hi20(%1)"
[(set_attr "type" "move")])
@@ -2851,7 +2880,7 @@ (define_insn "rint<mode>2"
[(set (match_operand:ANYF 0 "register_operand" "=f")
(unspec:ANYF [(match_operand:ANYF 1 "register_operand" "f")]
UNSPEC_FRINT))]
- ""
+ "TARGET_64BIT && TARGET_HARD_FLOAT"
"frint.<fmt>\t%0,%1"
[(set_attr "type" "fcvt")
(set_attr "mode" "<MODE>")])
@@ -3172,7 +3201,7 @@ (define_insn "loongarch_lddir_<d>"
(match_operand 2 "const_uimm5_operand")]
UNSPECV_LDDIR)
(clobber (mem:BLK (scratch)))]
- ""
+ "TARGET_64BIT || TARGET_32BIT_S"
"lddir\t%0,%1,%2"
[(set_attr "type" "load")
(set_attr "mode" "<MODE>")])
@@ -3182,7 +3211,7 @@ (define_insn "loongarch_ldpte_<d>"
(match_operand 1 "const_uimm5_operand")]
UNSPECV_LDPTE)
(clobber (mem:BLK (scratch)))]
- ""
+ "TARGET_64BIT || TARGET_32BIT_S"
"ldpte\t%0,%1"
[(set_attr "type" "load")
(set_attr "mode" "<MODE>")])
@@ -3260,7 +3289,7 @@ (define_insn "*rotr<mode>3"
[(set (match_operand:GPR 0 "register_operand" "=r,r")
(rotatert:GPR (match_operand:GPR 1 "register_operand" "r,r")
(match_operand:SI 2 "arith_operand" "r,I")))]
- ""
+ "TARGET_64BIT || TARGET_32BIT_S"
"rotr%i2.<d>\t%0,%1,%2"
[(set_attr "type" "shift,shift")
(set_attr "mode" "<MODE>")])
@@ -3270,7 +3299,7 @@ (define_insn "rotrsi3_extend"
(sign_extend:DI
(rotatert:SI (match_operand:SI 1 "register_operand" "r,r")
(match_operand:SI 2 "arith_operand" "r,I"))))]
- "TARGET_64BIT"
+ "TARGET_64BIT || TARGET_32BIT_S"
"rotr%i2.w\t%0,%1,%2"
[(set_attr "type" "shift,shift")
(set_attr "mode" "SI")])
@@ -3282,7 +3311,7 @@ (define_expand "rotl<mode>3"
(set (match_operand:GPR 0 "register_operand")
(rotatert:GPR (match_operand:GPR 1 "register_operand")
(match_dup 3)))]
- ""
+ "TARGET_64BIT || TARGET_32BIT_S"
{
operands[3] = gen_reg_rtx (SImode);
@@ -3305,7 +3334,7 @@ (define_insn "alsl<mode>3"
(plus:GPR (ashift:GPR (match_operand:GPR 1 "register_operand" "r")
(match_operand 2 "const_immalsl_operand" ""))
(match_operand:GPR 3 "register_operand" "r")))]
- ""
+ "TARGET_64BIT || TARGET_32BIT_S"
"alsl.<d>\t%0,%1,%3,%2"
[(set_attr "type" "arith")
(set_attr "mode" "<MODE>")])
@@ -3348,7 +3377,8 @@ (define_insn_and_split "<optab>_shift_reverse<X:mode>"
(ashift:X (match_operand:X 1 "register_operand" "r")
(match_operand:SI 2 "const_int_operand" "i"))
(match_operand:X 3 "const_int_operand" "i")))]
- "(const_immalsl_operand (operands[2], SImode)
+ "TARGET_64BIT
+ && (const_immalsl_operand (operands[2], SImode)
|| !<bitwise_operand> (operands[3], <MODE>mode))
&& loongarch_reassoc_shift_bitwise (<is_and>, operands[2], operands[3],
<MODE>mode)"
@@ -3430,7 +3460,7 @@ (define_insn "revb_2h"
[(set (match_operand:SI 0 "register_operand" "=r")
(rotatert:SI (bswap:SI (match_operand:SI 1 "register_operand" "r"))
(const_int 16)))]
- ""
+ "TARGET_64BIT || TARGET_32BIT_S"
"revb.2h\t%0,%1"
[(set_attr "type" "shift")])
@@ -3440,14 +3470,14 @@ (define_insn "revb_2h_extend"
(rotatert:SI
(bswap:SI (match_operand:SI 1 "register_operand" "r"))
(const_int 16))))]
- "TARGET_64BIT"
+ "TARGET_64BIT || TARGET_32BIT_S"
"revb.2h\t%0,%1"
[(set_attr "type" "shift")])
(define_insn "bswaphi2"
[(set (match_operand:HI 0 "register_operand" "=r")
(bswap:HI (match_operand:HI 1 "register_operand" "r")))]
- ""
+ "TARGET_64BIT || TARGET_32BIT_S"
"revb.2h\t%0,%1"
[(set_attr "type" "shift")])
@@ -3469,9 +3499,9 @@ (define_insn "*bswapsi2"
(define_expand "bswapsi2"
[(set (match_operand:SI 0 "register_operand" "=r")
(bswap:SI (match_operand:SI 1 "register_operand" "r")))]
- ""
+ "TARGET_64BIT || TARGET_32BIT_S"
{
- if (!TARGET_64BIT)
+ if (TARGET_32BIT_S)
{
rtx t = gen_reg_rtx (SImode);
emit_insn (gen_revb_2h (t, operands[1]));
@@ -3635,7 +3665,7 @@ (define_expand "cstore<mode>4"
(match_operator:SI 1 "loongarch_cstore_operator"
[(match_operand:GPR 2 "register_operand")
(match_operand:GPR 3 "nonmemory_operand")]))]
- ""
+ "TARGET_64BIT"
{
loongarch_expand_scc (operands);
DONE;
@@ -4463,7 +4493,7 @@ (define_insn "*bytepick_w_<bytepick_imm>"
(const_int <bytepick_w_lshiftrt_amount>))
(ashift:SI (match_operand:SI 2 "register_operand" "r")
(const_int bytepick_w_ashift_amount))))]
- ""
+ "TARGET_64BIT || TARGET_32BIT_S"
"bytepick.w\t%0,%1,%2,<bytepick_imm>"
[(set_attr "mode" "SI")])
@@ -4481,7 +4511,7 @@ (define_insn "bytepick_w_<bytepick_imm>_extend"
(zero_extract:DI (match_operand:DI 2 "register_operand" "r")
(const_int <bytepick_w_ashift_amount>)
(const_int <bitsize>))))]
- "TARGET_64BIT"
+ "TARGET_64BIT || TARGET_32BIT_S"
"bytepick.w\t%0,%2,%1,<bytepick_imm>"
[(set_attr "mode" "SI")])
@@ -4496,7 +4526,7 @@ (define_insn "bytepick_w_1_extend"
(zero_extract:DI (match_operand:DI 2 "register_operand" "r")
(const_int 8)
(const_int 24))))]
- "TARGET_64BIT"
+ "TARGET_64BIT || TARGET_32BIT_S"
"bytepick.w\t%0,%2,%1,1"
[(set_attr "mode" "SI")])
@@ -4526,7 +4556,7 @@ (define_insn "bitrev_4b"
[(set (match_operand:SI 0 "register_operand" "=r")
(unspec:SI [(match_operand:SI 1 "register_operand" "r")]
UNSPEC_BITREV_4B))]
- ""
+ "TARGET_64BIT || TARGET_32BIT_S"
"bitrev.4b\t%0,%1"
[(set_attr "type" "unknown")
(set_attr "mode" "SI")])
@@ -4535,7 +4565,7 @@ (define_insn "bitrev_8b"
[(set (match_operand:DI 0 "register_operand" "=r")
(unspec:DI [(match_operand:DI 1 "register_operand" "r")]
UNSPEC_BITREV_8B))]
- ""
+ "TARGET_64BIT"
"bitrev.8b\t%0,%1"
[(set_attr "type" "unknown")
(set_attr "mode" "DI")])
@@ -4543,7 +4573,7 @@ (define_insn "bitrev_8b"
(define_insn "@rbit<mode>"
[(set (match_operand:GPR 0 "register_operand" "=r")
(bitreverse:GPR (match_operand:GPR 1 "register_operand" "r")))]
- ""
+ "TARGET_64BIT || TARGET_32BIT_S"
"bitrev.<size>\t%0,%1"
[(set_attr "type" "unknown")
(set_attr "mode" "<MODE>")])
@@ -4562,7 +4592,7 @@ (define_insn "rbitsi_extended"
(define_insn "rbitqi"
[(set (match_operand:QI 0 "register_operand" "=r")
(bitreverse:QI (match_operand:QI 1 "register_operand" "r")))]
- ""
+ "TARGET_64BIT || TARGET_32BIT_S"
"bitrev.4b\t%0,%1"
[(set_attr "type" "unknown")
(set_attr "mode" "SI")])
@@ -4705,7 +4735,7 @@ (define_insn "loongarch_<crc>_w_<size>_w"
(unspec:SI [(match_operand:QHWD 1 "register_operand" "r")
(match_operand:SI 2 "register_operand" "r")]
CRC))]
- ""
+ "TARGET_64BIT"
"<crc>.w.<size>.w\t%0,%1,%2"
[(set_attr "type" "unknown")
(set_attr "mode" "<MODE>")])
@@ -4726,7 +4756,7 @@ (define_expand "crc_rev<mode>si4"
(match_operand:SI 1 "register_operand") ; old_chksum
(match_operand:SUBDI 2 "reg_or_0_operand") ; msg
(match_operand 3 "const_int_operand")] ; poly
- ""
+ "TARGET_64BIT"
{
unsigned HOST_WIDE_INT poly = UINTVAL (operands[3]);
rtx msg = operands[2];
@@ -4823,7 +4853,8 @@ (define_insn_and_split "*crc_combine"
(define_insn_and_rewrite "simple_load<mode>"
[(set (match_operand:LD_AT_LEAST_32_BIT 0 "register_operand" "=r,f")
(match_operand:LD_AT_LEAST_32_BIT 1 "mem_simple_ldst_operand" ""))]
- "loongarch_pre_reload_split ()
+ "(TARGET_64BIT || TARGET_32BIT_S)
+ && loongarch_pre_reload_split ()
&& la_opt_explicit_relocs == EXPLICIT_RELOCS_AUTO
&& (TARGET_CMODEL_NORMAL || TARGET_CMODEL_MEDIUM)"
"#"
@@ -4836,7 +4867,8 @@ (define_insn_and_rewrite
"simple_load_<su>ext<SUBDI:mode><GPR:mode>"
[(set (match_operand:GPR 0 "register_operand" "=r")
(any_extend:GPR
(match_operand:SUBDI 1 "mem_simple_ldst_operand" "")))]
- "loongarch_pre_reload_split ()
+ "(TARGET_64BIT || TARGET_32BIT_S)
+ && loongarch_pre_reload_split ()
&& la_opt_explicit_relocs == EXPLICIT_RELOCS_AUTO
&& (TARGET_CMODEL_NORMAL || TARGET_CMODEL_MEDIUM)"
"#"
@@ -4848,7 +4880,8 @@ (define_insn_and_rewrite
"simple_load_<su>ext<SUBDI:mode><GPR:mode>"
(define_insn_and_rewrite "simple_store<mode>"
[(set (match_operand:ST_ANY 0 "mem_simple_ldst_operand" "")
(match_operand:ST_ANY 1 "reg_or_0_operand" "r,f"))]
- "loongarch_pre_reload_split ()
+ "(TARGET_64BIT || TARGET_32BIT_S)
+ && loongarch_pre_reload_split ()
&& la_opt_explicit_relocs == EXPLICIT_RELOCS_AUTO
&& (TARGET_CMODEL_NORMAL || TARGET_CMODEL_MEDIUM)"
"#"
diff --git a/gcc/config/loongarch/predicates.md
b/gcc/config/loongarch/predicates.md
index 8460618b501..260e06bc695 100644
--- a/gcc/config/loongarch/predicates.md
+++ b/gcc/config/loongarch/predicates.md
@@ -291,7 +291,8 @@ (define_predicate "si_mask_operand"
(define_predicate "low_bitmask_operand"
(and (match_code "const_int")
- (match_test "low_bitmask_len (mode, INTVAL (op)) > 12")))
+ (match_test "low_bitmask_len (mode, INTVAL (op)) > 12")
+ (match_test "!TARGET_32BIT_R")))
(define_predicate "d_operand"
(and (match_code "reg")
@@ -402,6 +403,7 @@ (define_predicate "muldiv_target_operand"
(define_predicate "ins_zero_bitmask_operand"
(and (match_code "const_int")
+ (match_test "!TARGET_32BIT_R")
(match_test "low_bitmask_len (mode, \
~UINTVAL (op) | (~UINTVAL(op) - 1)) \
> 0")
diff --git a/gcc/config/loongarch/sync.md b/gcc/config/loongarch/sync.md
index 59959bbbadc..9995390a5d5 100644
--- a/gcc/config/loongarch/sync.md
+++ b/gcc/config/loongarch/sync.md
@@ -254,7 +254,7 @@ (define_insn "atomic_storeti_scq"
UNSPEC_ATOMIC_STORE))
(clobber (match_scratch:DI 2 "=&r"))]
"TARGET_64BIT && ISA_HAS_SCQ"
- "1:\\n\\tll.d\t$r0,%0\n\tmove\t%2,%1\n\tsc.q\t%2,%t1,%0\n\tbeqz\t%2,1b"
+ "1:\\n\\tll.d\t$r0,%0\n\tmove\t%2,%1\n\tsc.q\t%2,%t1,%0\n\tbeq\t%2,$zero,1b"
[(set (attr "length") (const_int 16))])
(define_expand "atomic_storeti"
@@ -392,14 +392,24 @@ (define_insn "atomic_fetch_nand_mask_inverted<mode>"
UNSPEC_SYNC_OLD_OP))
(clobber (match_scratch:GPR 3 "=&r"))]
""
- {
- return "1:\\n\\t"
- "ll.<d>\\t%0,%1\\n\\t"
- "orn\\t%3,%2,%0\\n\\t"
- "sc.<d>\\t%3,%1\\n\\t"
- "beqz\\t%3,1b";
- }
- [(set (attr "length") (const_int 16))])
+{
+ output_asm_insn ("1:", operands);
+ output_asm_insn ("ll.<d>\t%0,%1", operands);
+ if (TARGET_32BIT_R)
+ {
+ output_asm_insn ("nor\t%3,%0,$zero", operands);
+ output_asm_insn ("or\t%3,%2,%3", operands);
+ }
+ else
+ output_asm_insn ("orn\t%3,%2,%0", operands);
+ output_asm_insn ("sc.<d>\t%3,%1", operands);
+ output_asm_insn ("beq\t%3,$zero,1b", operands);
+ return "";
+}
+ [(set (attr "length") (if_then_else
+ (match_test "TARGET_32BIT_R")
+ (const_int 20)
+ (const_int 16)))])
(define_mode_iterator ALL_SC [GPR (TI "TARGET_64BIT && ISA_HAS_SCQ")])
(define_mode_attr _scq [(SI "") (DI "") (TI "_scq")])
@@ -489,7 +499,7 @@ (define_insn "atomic_exchangeti_scq"
output_asm_insn ("ld.d\t%t0,%b1,8", operands);
output_asm_insn ("move\t%3,%z2", operands);
output_asm_insn ("sc.q\t%3,%t2,%1", operands);
- output_asm_insn ("beqz\t%3,1b", operands);
+ output_asm_insn ("beq\t%3,$zero,1b", operands);
return "";
}
@@ -552,7 +562,7 @@ (define_insn "atomic_cas_value_strong<mode>"
output_asm_insn ("or%i3\t%5,$zero,%3", operands);
output_asm_insn ("sc.<size>\t%5,%1", operands);
- output_asm_insn ("beqz\t%5,1b", operands);
+ output_asm_insn ("beq\t%5,$zero,1b", operands);
output_asm_insn ("%T4b\t3f", operands);
output_asm_insn ("2:", operands);
output_asm_insn ("%G4", operands);
@@ -838,7 +848,7 @@ (define_insn "atomic_compare_and_swapti_scq"
output_asm_insn ("sc.q\t%7,%t3,%1", operands);
/* Check if sc.q has done the store. */
- output_asm_insn ("beqz\t%7,1b", operands);
+ output_asm_insn ("beq\t%7,$zero,1b", operands);
/* Jump over the mod_f barrier if sc.q has succeeded. */
output_asm_insn ("%T4b\t3f", operands);
@@ -992,7 +1002,7 @@ (define_insn "atomic_cas_value_exchange_7_<mode>"
"and\\t%7,%0,%z3\\n\\t"
"or%i5\\t%7,%7,%5\\n\\t"
"sc.<size>\\t%7,%1\\n\\t"
- "beqz\\t%7,1b\\n\\t";
+ "beq\\t%7,$zero,1b\\n\\t";
}
[(set (attr "length") (const_int 20))])
@@ -1089,7 +1099,7 @@ (define_insn "atomic_fetch_<amop_ti_fetch>ti_scq"
}
output_asm_insn ("sc.q\t%3,%4,%1", operands);
- output_asm_insn ("beqz\t%3,1b", operands);
+ output_asm_insn ("beq\t%3,$zero,1b", operands);
return "";
}
diff --git a/include/longlong.h b/include/longlong.h
index 5ae250f7192..9429e90e0d1 100644
--- a/include/longlong.h
+++ b/include/longlong.h
@@ -594,11 +594,7 @@ extern UDItype __umulsidi3 (USItype, USItype);
#endif
#ifdef __loongarch__
-# if W_TYPE_SIZE == 32
-# define count_leading_zeros(count, x) ((count) = __builtin_clz (x))
-# define count_trailing_zeros(count, x) ((count) = __builtin_ctz (x))
-# define COUNT_LEADING_ZEROS_0 32
-# elif W_TYPE_SIZE == 64
+# if W_TYPE_SIZE == 64
# define count_leading_zeros(count, x) ((count) = __builtin_clzll (x))
# define count_trailing_zeros(count, x) ((count) = __builtin_ctzll (x))
# define COUNT_LEADING_ZEROS_0 64
--
2.34.1