Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cfgcleanup] MIPS BE: wrong code generates under "-Os -mbranch-cost=1" #4

Open
xiangzhai opened this issue Jan 21, 2018 · 0 comments
Open
Labels
Milestone

Comments

@xiangzhai
Copy link

xiangzhai commented Jan 21, 2018

Hi fellows,

As PR83496 mentioned:
Testcase is wrongly lowering to:

	.file	1 "gcc-pr83496.c"
	.section .mdebug.abi64
	.previous
	.nan	legacy
	.module	fp=64
	.module	oddspreg
	.abicalls
	.text
	.align	2
	.globl	mytest
	.set	nomips16
	.set	nomicromips
	.ent	mytest
	.type	mytest, @function
mytest:
	.frame	$sp,0,$31		# vars= 0, regs= 0/0, args= 0, gp= 0
	.mask	0x00000000,0
	.fmask	0x00000000,0
	.set	noreorder
	.set	nomacro
	lw	$3,8($4)
	li	$2,1			# 0x1
	beq	$3,$2,.L3
	nop # <-- it should say "li v0,1" instead of nop

	lw	$3,0($4)
	slt	$3,$3,2
	beq	$3,$0,.L5
	nop

	ld	$2,16($4)
	ld	$2,0($2)
	sltu	$3,$5,$2
	bne	$3,$0,.L5
	nop

	sltu	$2,$2,$5
	j	$31
	subu	$2,$0,$2

.L3:
	j	$31
	li	$2,-1			# 0xffffffffffffffff

.L5:
	j	$31
	li	$2,1			# 0x1

	.set	macro
	.set	reorder
	.end	mytest
	.size	mytest, .-mytest
	.section	.text.startup,"ax",@progbits
	.align	2
	.globl	main
	.set	nomips16
	.set	nomicromips
	.ent	main
	.type	main, @function
main:
	.frame	$sp,0,$31		# vars= 0, regs= 0/0, args= 0, gp= 0
	.mask	0x00000000,0
	.fmask	0x00000000,0
	.set	noreorder
	.set	nomacro
	j	$31
	move	$2,$0

	.set	macro
	.set	reorder
	.end	main
	.size	main, .-main
	.ident	"GCC: (GNU) 5.5.0 20171010 (LLVM China GCC 5.5-2018.01)"

GCC 8.x still reproducible the key point might be bb_is_just_return:

commit 01b8ebb6e5940eca6d158dc793424a6580c90998
Author: segher <segher@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Wed May 4 20:54:47 2016 +0000

    cfgcleanup: Fold jumps and conditional branches with returns
    
    This patch makes cfgcleanup optimize jumps to returns.  There are three
    cases this handles:
    
    -- A jump to a return; this is simplified to just that return.
    -- A conditional branch to a return; simplified to a conditional return.
    -- A conditional branch that falls through to a return.  This is simplified
       to a conditional return (with the condition inverted), falling through
       to a jump to the original destination.  That jump can then be optimized
       further, as usual.
    
    This handles all cases the current function.c does, and a few it misses.
    
    
            * cfgcleanup.c (bb_is_just_return): New function.
            (try_optimize_cfg): Simplify jumps to return, branches to return,
            and branches around return.

Regards,
Leslie Zhai

@xiangzhai xiangzhai added the bug label Jan 21, 2018
@xiangzhai xiangzhai added this to the gcc-8-branch milestone Feb 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant