Skip to content

Commit 78e2087

Browse files
Claudiu Zissulescuartemiy-volkov
authored andcommitted
arc64: Add BBIT[0/1][L] pattern
1 parent 0a133fe commit 78e2087

File tree

4 files changed

+104
-18
lines changed

4 files changed

+104
-18
lines changed

gcc/config/arc64/arc64.c

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,7 +1211,6 @@ get_arc64_condition_code (rtx comparison)
12111211
switch (GET_MODE (XEXP (comparison, 0)))
12121212
{
12131213
case E_CCmode:
1214-
case E_SImode:
12151214
switch (GET_CODE (comparison))
12161215
{
12171216
case EQ : return ARC_CC_EQ;
@@ -1237,6 +1236,8 @@ get_arc64_condition_code (rtx comparison)
12371236
default : gcc_unreachable ();
12381237
}
12391238
case E_CC_Zmode:
1239+
case E_DImode: /* bbit instructions. */
1240+
case E_SImode:
12401241
switch (GET_CODE (comparison))
12411242
{
12421243
case EQ : return ARC_CC_EQ;
@@ -3499,29 +3500,32 @@ arc64_rtx_costs (rtx x, machine_mode mode, rtx_code outer,
34993500

35003501
case CONST_INT:
35013502
{
3502-
bool limm_p = true;
35033503
HOST_WIDE_INT imm = INTVAL (x);
35043504

35053505
/* In general any 32bit constant can be loaded immediately,
35063506
however, when we compile for speed, we try to avoid
35073507
them. */
3508+
*cost = 0;
35083509
if (UNSIGNED_INT6 (imm))
3509-
limm_p = false;
3510+
return true;
35103511
else
35113512
switch (outer)
35123513
{
35133514
case SET:
35143515
if (SIGNED_INT12 (imm))
3515-
limm_p = false;
3516+
return true;
35163517
break;
35173518

35183519
default:
35193520
break;
35203521
}
3521-
3522-
*cost = limm_p ? cost_limm : 0;
3523-
return true;
35243522
}
3523+
/* FALLTHRU */
3524+
case CONST:
3525+
case LABEL_REF:
3526+
case SYMBOL_REF:
3527+
*cost = cost_limm;
3528+
return true;
35253529

35263530
case ASHIFT:
35273531
case ASHIFTRT:
@@ -3540,6 +3544,18 @@ arc64_rtx_costs (rtx x, machine_mode mode, rtx_code outer,
35403544
*cost = COSTS_N_INSNS (12);
35413545
return true;
35423546

3547+
case EQ:
3548+
case NE:
3549+
if (outer == IF_THEN_ELSE
3550+
&& (GET_CODE (XEXP (x, 0)) == AND
3551+
|| GET_CODE (XEXP (x, 0)) == ZERO_EXTRACT)
3552+
&& XEXP (x, 1) == const0_rtx)
3553+
{
3554+
*cost = 0;
3555+
return true;
3556+
}
3557+
break;
3558+
35433559
default:
35443560
break;
35453561
}

gcc/config/arc64/arc64.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ extern const enum reg_class arc64_regno_to_regclass[];
457457
#define SIGNED_INT14_SHIFTED(X,S) (VERIFY_SHIFT(X,S) && SIGNED_INT12(X >> S))
458458
#define SIGNED_INT15_SHIFTED(X,S) (VERIFY_SHIFT(X,S) && SIGNED_INT12(X >> S))
459459

460+
#define IS_POWEROF2_P(X) (! ( (X) & ((X) - 1)) && (X))
460461

461462
/* These assume that REGNO is a hard or pseudo reg number.
462463
They give nonzero only if REGNO is a hard reg of the suitable class

gcc/config/arc64/arc64.md

Lines changed: 76 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -422,17 +422,17 @@
422422
(define_attr "cost" "" (const_int 0))
423423

424424
(define_attr "type" "abs, adcl, add, addhl, addl, and, andl, asl,
425-
asll, asr, asrl, atldop, atldlop, bclr, bic, bl, block, bmsk, branch,
426-
branchcc, brk, bset, bsetl, btst, bxor, bxorl, cmp, dbnz, dmb, dmpywh,
427-
ex, div, divl, ext, fadd, fcmp, fsub, fmul, fdiv, fh2s, fmin, fmax,
428-
fsgnj, fsgnjx, fsgnjn, fmadd, fmov, fmsub, fnmadd, fnmsub, fsqrt,
429-
frnd, fs2d, fs2h, fd2s, int2fp, uint2fp, fp2int, fp2uint, ffs, fls,
430-
flag, jl, jump, ld, llock, lsr, lsrl, lr, max, maxl, min, minl, move,
431-
movecc, mod, modl, neg, nop, norm, normh, norml, mac, mpy, mpyl, not,
432-
notl, or, orl, return, ror, rol, sbcl, scond, setcc, sex, sr, st, sub,
433-
subl, swap, swapl, swape, swapel, sync, tst, trap, qmach, qmpyh, udiv,
434-
udivl, umod, umodl, unknown, vadd, vsub, vmac2h, vmpy2h, vfadd, vfext,
435-
vfins, vfsub, vfmul, vfdiv, vfrep, vpack, xbfu, xor, xorl"
425+
asll, asr, asrl, atldop, atldlop, bbit, bclr, bic, bl, block, bmsk,
426+
branch, branchcc, brk, bset, bsetl, btst, bxor, bxorl, cmp, dbnz, dmb,
427+
dmpywh, ex, div, divl, ext, fadd, fcmp, fsub, fmul, fdiv, fh2s, fmin,
428+
fmax, fsgnj, fsgnjx, fsgnjn, fmadd, fmov, fmsub, fnmadd, fnmsub,
429+
fsqrt, frnd, fs2d, fs2h, fd2s, int2fp, uint2fp, fp2int, fp2uint, ffs,
430+
fls, flag, jl, jump, ld, llock, lsr, lsrl, lr, max, maxl, min, minl,
431+
move, movecc, mod, modl, neg, nop, norm, normh, norml, mac, mpy, mpyl,
432+
not, notl, or, orl, return, ror, rol, sbcl, scond, setcc, sex, sr, st,
433+
sub, subl, swap, swapl, swape, swapel, sync, tst, trap, qmach, qmpyh,
434+
udiv, udivl, umod, umodl, unknown, vadd, vsub, vmac2h, vmpy2h, vfadd,
435+
vfext, vfins, vfsub, vfmul, vfdiv, vfrep, vpack, xbfu, xor, xorl"
436436
(const_string "unknown"))
437437

438438
(define_attr "iscompact" "yes,no,maybe" (const_string "no"))
@@ -1345,6 +1345,71 @@ vfins, vfsub, vfmul, vfdiv, vfrep, vpack, xbfu, xor, xorl"
13451345
[(set_attr "type" "jump")
13461346
(set_attr "length" "2,4")])
13471347

1348+
;; combiner patterns used to match bbit0/1 instructions.
1349+
;; Unfortunately, I cannot use splitting for this pattern as the
1350+
;; insn length is know very late during compilation process.
1351+
(define_insn "*bbit_and"
1352+
[(set (pc)
1353+
(if_then_else
1354+
(match_operator 3 "equality_comparison_operator"
1355+
[(and:GPI
1356+
(match_operand:GPI 1 "register_operand" "r")
1357+
(match_operand 2 "bbitimm_operand" ""))
1358+
(const_int 0)])
1359+
(label_ref (match_operand 0 "" ""))
1360+
(pc)))
1361+
(clobber (reg:CC_ZN CC_REGNUM))]
1362+
"!CROSSING_JUMP_P (insn)"
1363+
{
1364+
operands[2] = GEN_INT (exact_log2 (INTVAL (operands[2])));
1365+
switch (get_attr_length (insn))
1366+
{
1367+
case 4:
1368+
return (GET_CODE (operands[3]) == EQ
1369+
? \"bbit0<sfxtab>\\t%1,%2,%l0\" : \"bbit1<sfxtab>\\t%1,%2,%l0\");
1370+
default:
1371+
return \"btst<sfxtab>\\t%1,%2\\n\\tb%m3\\t%l0\";
1372+
}
1373+
}
1374+
[(set_attr "type" "bbit")
1375+
(set (attr "length")
1376+
(if_then_else
1377+
(and (ge (minus (match_dup 0) (pc)) (const_int -254))
1378+
(le (minus (match_dup 0) (pc)) (const_int 250)))
1379+
(const_int 4)
1380+
(const_int 8)))])
1381+
1382+
(define_insn "*bbit_zext"
1383+
[(set (pc)
1384+
(if_then_else
1385+
(match_operator 3 "equality_comparison_operator"
1386+
[(zero_extract:GPI
1387+
(match_operand:GPI 1 "register_operand" "r")
1388+
(const_int 1)
1389+
(match_operand:GPI 2 "nonmemory_operand" "ir"))
1390+
(const_int 0)])
1391+
(label_ref (match_operand 0 "" ""))
1392+
(pc)))
1393+
(clobber (reg:CC_ZN CC_REGNUM))]
1394+
"!CROSSING_JUMP_P (insn)"
1395+
{
1396+
switch (get_attr_length (insn))
1397+
{
1398+
case 4:
1399+
return (GET_CODE (operands[3]) == EQ
1400+
? \"bbit0<sfxtab>\\t%1,%2,%l0\" : \"bbit1<sfxtab>\\t%1,%2,%l0\");
1401+
default:
1402+
return \"btst<sfxtab>\\t%1,%2\\n\\tb%m3\\t%l0\";
1403+
}
1404+
}
1405+
[(set_attr "type" "bbit")
1406+
(set (attr "length")
1407+
(if_then_else
1408+
(and (ge (minus (match_dup 0) (pc)) (const_int -254))
1409+
(le (minus (match_dup 0) (pc)) (const_int 250)))
1410+
(const_int 4)
1411+
(const_int 8)))])
1412+
13481413
;; -------------------------------------------------------------------
13491414
;; Sign/Zero extension
13501415
;; -------------------------------------------------------------------

gcc/config/arc64/predicates.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,7 @@
204204
(define_predicate "unsign_immediate_operand"
205205
(and (match_code "const_int")
206206
(match_test "UNSIGNED_INT16 (INTVAL (op))")))
207+
208+
(define_predicate "bbitimm_operand"
209+
(and (match_code "const_int")
210+
(match_test "IS_POWEROF2_P (INTVAL (op))")))

0 commit comments

Comments
 (0)