[PATCH 3/4] simplify CGOTO(SEL(x, L1, L2)) into CBR x, L1, L2

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



A computed goto having as operand a select of 2 statically known addresses
(OP_SETVAL/EXPR_LABEL) is equivalent to a simple conditional branch.

Simplify such computed goto into the corresponding OP_CBR

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 simplify.c                 | 22 ++++++++++++++++++++++
 validation/optim/cgoto02.c |  1 -
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/simplify.c b/simplify.c
index 132d408f59f1..24ecf074206e 100644
--- a/simplify.c
+++ b/simplify.c
@@ -2112,13 +2112,35 @@ found:
 	return REPEAT_CSE;
 }
 
+static struct basic_block *is_label(pseudo_t pseudo)
+{
+	struct expression *expr;
+	struct instruction *def;
+
+	if (DEF_OPCODE(def, pseudo) != OP_SETVAL)
+		return NULL;
+	expr = def->val;
+	if (expr->type != EXPR_LABEL)
+		return NULL;
+	return expr->symbol->bb_target;
+}
+
 static int simplify_cgoto(struct instruction *insn)
 {
 	struct basic_block *target, *bb = insn->bb;
+	struct basic_block *bbt, *bbf;
 	struct instruction *def;
 	struct multijmp *jmp;
 
 	switch (DEF_OPCODE(def, insn->src)) {
+	case OP_SEL:	// CGOTO(SEL(x, L1, L2)) --> CBR x, L1, L2
+		if ((bbt = is_label(def->src2)) && (bbf = is_label(def->src3))) {
+			insn->opcode = OP_CBR;
+			insn->bb_true = bbt;
+			insn->bb_false = bbf;
+			return replace_pseudo(insn, &insn->src1, def->cond);
+		}
+		break;
 	case OP_SETVAL:
 		if (def->val->type != EXPR_LABEL)
 			break;
diff --git a/validation/optim/cgoto02.c b/validation/optim/cgoto02.c
index 5869d5b4a24d..932c3164e5ee 100644
--- a/validation/optim/cgoto02.c
+++ b/validation/optim/cgoto02.c
@@ -11,7 +11,6 @@ l2:
 /*
  * check-name: cgoto02
  * check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
  *
  * check-output-ignore
  * check-output-returns: %arg1
-- 
2.29.2




[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux