Commit efea32cf authored by Andreas Klebinger's avatar Andreas Klebinger Committed by Ben Gamari

Check if both branches of an Cmm if have the same target.

This for some reason or the other and makes it into the final
binary. I've added the check to ContFlowOpt as that seems
like a logical place for this.

In a regular nofib run there were 30 occurences of this pattern.

Test Plan: ci

Reviewers: bgamari, simonmar, dfeuer, jrtc27, tdammers

Reviewed By: bgamari, simonmar

Subscribers: tdammers, dfeuer, rwbarton, thomie, carter

GHC Trac Issues: #15188

Differential Revision:
parent 767536cc
......@@ -254,8 +254,8 @@ blockConcat splitting_procs g@CmmGraph { g_entry = entry_id }
-- unconditional jump to a block that can be shortcut.
| Nothing <- callContinuation_maybe last
= let oldSuccs = successors last
newSuccs = successors swapcond_last
in ( mapInsert bid (blockJoinTail head swapcond_last) blocks
newSuccs = successors rewrite_last
in ( mapInsert bid (blockJoinTail head rewrite_last) blocks
, shortcut_map
, if oldSuccs == newSuccs
then backEdges
......@@ -283,8 +283,13 @@ blockConcat splitting_procs g@CmmGraph { g_entry = entry_id }
Just b | Just dest <- canShortcut b -> dest
_otherwise -> l
-- See Note [Invert Cmm conditionals]
-- Sometimes we can get rid of the conditional completely.
| CmmCondBranch _cond t f _l <- shortcut_last
, t == f
= CmmBranch t
-- See Note [Invert Cmm conditionals]
| CmmCondBranch cond t f l <- shortcut_last
, hasOnePredecessor t -- inverting will make t a fallthrough
, likelyTrue l || (numPreds f > 1)
include $(TOP)/mk/
include $(TOP)/mk/
'$(TEST_HC)' $(TEST_HC_OPTS) -c -O -ddump-cmm-cps -dsuppress-all T15188.cmm | grep if ; echo $$?
func(bits64 r2) {
if (r2 == 0) { goto bar; } else { goto bar; }
return (1);
# Verify that we optimize away conditional branches which always jump
# to the same target.
test('T15188', normal, run_command, ['$MAKE -s --no-print-directory T15188'])
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment