Skip to content

Commit 297ef07

Browse files
committed
Revert "microblaze: Remove -Os shift optimizations that emits potentially dead code"
This reverts commit 986c54f. Signed-off-by: Alp Sayin <alpsayin@gmail.com>
1 parent 986c54f commit 297ef07

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

gcc/config/microblaze/microblaze.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2051,6 +2051,27 @@ else
20512051
(set_attr "length" "8")]
20522052
)
20532053

2054+
(define_insn "*ashlsi3_with_size_opt"
2055+
[(set (match_operand:SI 0 "register_operand" "=&d")
2056+
(ashift:SI (match_operand:SI 1 "register_operand" "d")
2057+
(match_operand:SI 2 "immediate_operand" "I")))]
2058+
"(INTVAL (operands[2]) > 5 && optimize_size)"
2059+
{
2060+
operands[3] = gen_rtx_REG (SImode, MB_ABI_ASM_TEMP_REGNUM);
2061+
2062+
output_asm_insn ("ori\t%3,r0,%2", operands);
2063+
if (REGNO (operands[0]) != REGNO (operands[1]))
2064+
output_asm_insn ("addk\t%0,%1,r0", operands);
2065+
2066+
output_asm_insn ("addik\t%3,%3,-1", operands);
2067+
output_asm_insn ("bneid\t%3,.-4", operands);
2068+
return "addk\t%0,%0,%0";
2069+
}
2070+
[(set_attr "type" "multi")
2071+
(set_attr "mode" "SI")
2072+
(set_attr "length" "20")]
2073+
)
2074+
20542075
(define_insn "*ashlsi3_with_rotate"
20552076
[(set (match_operand:SI 0 "register_operand" "=&d")
20562077
(ashift:SI (match_operand:SI 1 "register_operand" "d")
@@ -2249,6 +2270,27 @@ else
22492270
(set_attr "length" "4,4")]
22502271
)
22512272

2273+
(define_insn "*ashrsi3_with_size_opt"
2274+
[(set (match_operand:SI 0 "register_operand" "=&d")
2275+
(ashiftrt:SI (match_operand:SI 1 "register_operand" "d")
2276+
(match_operand:SI 2 "immediate_operand" "I")))]
2277+
"(INTVAL (operands[2]) > 5 && optimize_size)"
2278+
{
2279+
operands[3] = gen_rtx_REG (SImode, MB_ABI_ASM_TEMP_REGNUM);
2280+
2281+
output_asm_insn ("ori\t%3,r0,%2", operands);
2282+
if (REGNO (operands[0]) != REGNO (operands[1]))
2283+
output_asm_insn ("addk\t%0,%1,r0", operands);
2284+
2285+
output_asm_insn ("addik\t%3,%3,-1", operands);
2286+
output_asm_insn ("bneid\t%3,.-4", operands);
2287+
return "sra\t%0,%0";
2288+
}
2289+
[(set_attr "type" "arith")
2290+
(set_attr "mode" "SI")
2291+
(set_attr "length" "20")]
2292+
)
2293+
22522294
(define_insn "*ashrsi_inline"
22532295
[(set (match_operand:SI 0 "register_operand" "=&d")
22542296
(ashiftrt:SI (match_operand:SI 1 "register_operand" "d")
@@ -2422,6 +2464,27 @@ else
24222464
(set_attr "length" "4,4")]
24232465
)
24242466

2467+
(define_insn "*lshrsi3_with_size_opt"
2468+
[(set (match_operand:SI 0 "register_operand" "=&d")
2469+
(lshiftrt:SI (match_operand:SI 1 "register_operand" "d")
2470+
(match_operand:SI 2 "immediate_operand" "I")))]
2471+
"(INTVAL (operands[2]) > 5 && optimize_size)"
2472+
{
2473+
operands[3] = gen_rtx_REG (SImode, MB_ABI_ASM_TEMP_REGNUM);
2474+
2475+
output_asm_insn ("ori\t%3,r0,%2", operands);
2476+
if (REGNO (operands[0]) != REGNO (operands[1]))
2477+
output_asm_insn ("addk\t%0,%1,r0", operands);
2478+
2479+
output_asm_insn ("addik\t%3,%3,-1", operands);
2480+
output_asm_insn ("bneid\t%3,.-4", operands);
2481+
return "srl\t%0,%0";
2482+
}
2483+
[(set_attr "type" "multi")
2484+
(set_attr "mode" "SI")
2485+
(set_attr "length" "20")]
2486+
)
2487+
24252488
(define_insn "*lshrsi_inline"
24262489
[(set (match_operand:SI 0 "register_operand" "=&d")
24272490
(lshiftrt:SI (match_operand:SI 1 "register_operand" "d")
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* { dg-options "-Os -mno-xl-barrel-shift" } */
2+
3+
void testfunc(void)
4+
{
5+
unsigned volatile int z = 8192;
6+
z >>= 8;
7+
}
8+
/* { dg-final { scan-assembler-not "\bsrli" } } */
9+
/* { dg-final { scan-assembler "\ori\tr18,r0" } } */
10+
/* { dg-final { scan-assembler "addk\tr(\[0-9]\|\[1-2]\[0-9]\|3\[0-1]),r(\[0-9]\|\[1-2]\[0-9]\|3\[0-1]),r0" } } */
11+
/* { dg-final { scan-assembler "addik\tr18,r18,-1" } } */
12+
/* { dg-final { scan-assembler "bneid\tr18,.-4" } } */
13+
/* { dg-final { scan-assembler "\srl\tr(\[0-9]\|\[1-2]\[0-9]\|3\[0-1]),r(\[0-9]\|\[1-2]\[0-9]\|3\[0-1])" } } */

0 commit comments

Comments
 (0)