* [PATCH 1/6] fix boolean context for OP_AND_BOOL & OP_OR_BOOL
2017-04-12 19:33 [PATCH 0/6] fix boolean context Luc Van Oostenryck
@ 2017-04-12 19:33 ` Luc Van Oostenryck
2017-04-12 19:33 ` [PATCH 2/6] simplify intermediate casts in boolean expressions Luc Van Oostenryck
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Luc Van Oostenryck @ 2017-04-12 19:33 UTC (permalink / raw)
To: linux-sparse; +Cc: Christopher Li, Luc Van Oostenryck
Current simplification of 'x && 1 --> x' and its dual
'x || 0 --> x' are wrong because the '||' and '&&' operators
demand that their operands are first compared against zero
which then always give a boolean valued result.
For example: '3 && 1' is not equal to '3' but to '1'.
The correct simplification is thus 'x && 1 --> x != 0' and
'x || 0 --> x != 0'.
Fix this by always first doing the comparison against zero
before generating the OP_AND_BOOL and OP_OR_BOOL instructions.
Note: of course, we could decide that the semantic of OP_AND_BOOL
and OP_OR_BOOL is that these ops take care themselves of
making a boolean context (which I think was why these
ops were created) but then these simplifications cannot be
done (or when they are done, we need to add the comparison
against zero).
Fixes: b85ec4bb7f5b1c522d7c71782dbd9cf1c4c49b2f
Fixes: a0886db12307d2633b04ec44342099a2955794a5
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
linearize.c | 42 +++++++++++++++++++++++++++++++--
validation/optim/bool-context-fp.c | 48 ++++++++++++++++++++++++++++++++++++++
validation/optim/bool-context.c | 12 ++++++++++
validation/optim/bool-simplify.c | 8 +++++--
4 files changed, 106 insertions(+), 4 deletions(-)
create mode 100644 validation/optim/bool-context.c
diff --git a/linearize.c b/linearize.c
index 9fda0a1ad..e730ab56f 100644
--- a/linearize.c
+++ b/linearize.c
@@ -1209,6 +1209,31 @@ static int map_opcode(int opcode, struct symbol *ctype)
return opcode;
}
+static inline pseudo_t add_convert_to_bool(struct entrypoint *ep, pseudo_t src, struct symbol *type)
+{
+ pseudo_t zero;
+ int op;
+
+ if (is_bool_type(type))
+ return src;
+ if (is_float_type(type)) {
+ zero = add_setfval(ep, type, 0.0);
+ op = map_opcode(OP_SET_NE, type);
+ } else {
+ zero = value_pseudo(0);
+ op = OP_SET_NE;
+ }
+ return add_binary_op(ep, &bool_ctype, op, src, zero);
+}
+
+static pseudo_t linearize_expression_to_bool(struct entrypoint *ep, struct expression *expr)
+{
+ pseudo_t dst;
+ dst = linearize_expression(ep, expr);
+ dst = add_convert_to_bool(ep, dst, expr->ctype);
+ return dst;
+}
+
static pseudo_t linearize_assignment(struct entrypoint *ep, struct expression *expr)
{
struct access_data ad = { NULL, };
@@ -1351,6 +1376,19 @@ static pseudo_t linearize_call_expression(struct entrypoint *ep, struct expressi
return retval;
}
+static pseudo_t linearize_binop_bool(struct entrypoint *ep, struct expression *expr)
+{
+ pseudo_t src1, src2, dst;
+ int op = (expr->op == SPECIAL_LOGICAL_OR) ? OP_OR_BOOL : OP_AND_BOOL;
+
+ src1 = linearize_expression_to_bool(ep, expr->left);
+ src2 = linearize_expression_to_bool(ep, expr->right);
+ dst = add_binary_op(ep, &bool_ctype, op, src1, src2);
+ if (expr->ctype != &bool_ctype)
+ dst = cast_pseudo(ep, dst, &bool_ctype, expr->ctype);
+ return dst;
+}
+
static pseudo_t linearize_binop(struct entrypoint *ep, struct expression *expr)
{
pseudo_t src1, src2, dst;
@@ -1361,8 +1399,6 @@ static pseudo_t linearize_binop(struct entrypoint *ep, struct expression *expr)
['|'] = OP_OR, ['^'] = OP_XOR,
[SPECIAL_LEFTSHIFT] = OP_SHL,
[SPECIAL_RIGHTSHIFT] = OP_LSR,
- [SPECIAL_LOGICAL_AND] = OP_AND_BOOL,
- [SPECIAL_LOGICAL_OR] = OP_OR_BOOL,
};
int op;
@@ -1647,6 +1683,8 @@ pseudo_t linearize_expression(struct entrypoint *ep, struct expression *expr)
return linearize_call_expression(ep, expr);
case EXPR_BINOP:
+ if (expr->op == SPECIAL_LOGICAL_AND || expr->op == SPECIAL_LOGICAL_OR)
+ return linearize_binop_bool(ep, expr);
return linearize_binop(ep, expr);
case EXPR_LOGICAL:
diff --git a/validation/optim/bool-context-fp.c b/validation/optim/bool-context-fp.c
index ad075c56e..6b3e8d181 100644
--- a/validation/optim/bool-context-fp.c
+++ b/validation/optim/bool-context-fp.c
@@ -5,6 +5,10 @@ bool bfexp(float a) { return (bool)a; }
bool bfnot(float a) { return !a; }
int ifnot(float a) { return !a; }
+bool bfior(float a, float b) { return a || b; }
+int ifior(float a, float b) { return a || b; }
+bool bfand(float a, float b) { return a && b; }
+int ifand(float a, float b) { return a && b; }
/*
* check-name: bool context fp
@@ -43,5 +47,49 @@ ifnot:
ret.32 %r16
+bfior:
+.L8:
+ <entry-point>
+ setfval.32 %r19 <- 0.000000
+ fcmpune.1 %r20 <- %arg1, %r19
+ fcmpune.1 %r23 <- %arg2, %r19
+ or-bool.1 %r24 <- %r23, %r20
+ setne.1 %r26 <- %r24, $0
+ ret.1 %r26
+
+
+ifior:
+.L10:
+ <entry-point>
+ setfval.32 %r29 <- 0.000000
+ fcmpune.1 %r30 <- %arg1, %r29
+ fcmpune.1 %r33 <- %arg2, %r29
+ or-bool.1 %r34 <- %r33, %r30
+ cast.32 %r35 <- (1) %r34
+ ret.32 %r35
+
+
+bfand:
+.L12:
+ <entry-point>
+ setfval.32 %r38 <- 0.000000
+ fcmpune.1 %r39 <- %arg1, %r38
+ fcmpune.1 %r42 <- %arg2, %r38
+ and-bool.1 %r43 <- %r42, %r39
+ setne.1 %r45 <- %r43, $0
+ ret.1 %r45
+
+
+ifand:
+.L14:
+ <entry-point>
+ setfval.32 %r48 <- 0.000000
+ fcmpune.1 %r49 <- %arg1, %r48
+ fcmpune.1 %r52 <- %arg2, %r48
+ and-bool.1 %r53 <- %r52, %r49
+ cast.32 %r54 <- (1) %r53
+ ret.32 %r54
+
+
* check-output-end
*/
diff --git a/validation/optim/bool-context.c b/validation/optim/bool-context.c
new file mode 100644
index 000000000..11326d391
--- /dev/null
+++ b/validation/optim/bool-context.c
@@ -0,0 +1,12 @@
+#define bool _Bool
+
+bool bool_ior(int a, int b) { return a || b; }
+bool bool_and(int a, int b) { return a && b; }
+
+/*
+ * check-name: bool-context
+ * check-command: test-linearize -Wno-decl $file
+ * check-output-ignore
+ *
+ * check-output-pattern-4-times: setne\\..* %arg[12]
+ */
diff --git a/validation/optim/bool-simplify.c b/validation/optim/bool-simplify.c
index e0ff1c2d4..05be11497 100644
--- a/validation/optim/bool-simplify.c
+++ b/validation/optim/bool-simplify.c
@@ -32,13 +32,17 @@ and_0:
and_1:
.L2:
<entry-point>
- ret.32 %arg1
+ setne.1 %r8 <- %arg1, $0
+ cast.32 %r11 <- (1) %r8
+ ret.32 %r11
or_0:
.L4:
<entry-point>
- ret.32 %arg1
+ setne.1 %r14 <- %arg1, $0
+ cast.32 %r17 <- (1) %r14
+ ret.32 %r17
or_1:
--
2.12.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/6] simplify intermediate casts in boolean expressions
2017-04-12 19:33 [PATCH 0/6] fix boolean context Luc Van Oostenryck
2017-04-12 19:33 ` [PATCH 1/6] fix boolean context for OP_AND_BOOL & OP_OR_BOOL Luc Van Oostenryck
@ 2017-04-12 19:33 ` Luc Van Oostenryck
2017-04-12 19:33 ` [PATCH 3/6] avoid useless compare with zero Luc Van Oostenryck
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Luc Van Oostenryck @ 2017-04-12 19:33 UTC (permalink / raw)
To: linux-sparse; +Cc: Christopher Li, Luc Van Oostenryck
For example:
int ibior(bool a) { return a || a; }
before simplification gives:
<entry-point>
setne.1 %r40 <- %arg1
setne.1 %r42 <- %arg2
or.1 %r43 <- %r40, %r42
cast.32 %r44 <- (1) %r43
ret.32 %r44
after simplification of the 'or', it used to give:
setne.1 %r40 <- %arg1, $0
cast.32 %r44 <- (1) %r40
ret.32 %r44
and now give:
setne.32 %r44 <- %arg1, $0
ret.32 %r44
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
simplify.c | 17 +++++++++++++++++
validation/optim/bool-simplify.c | 6 ++----
2 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/simplify.c b/simplify.c
index b46acd9c2..09d7ae056 100644
--- a/simplify.c
+++ b/simplify.c
@@ -982,6 +982,23 @@ static int simplify_cast(struct instruction *insn)
goto simplify;
}
+ if (insn->opcode == OP_CAST) {
+ struct instruction *def = src->def;
+ if (!def)
+ return 0;
+ switch (def->opcode) {
+ case OP_BINCMP ... OP_BINCMP_END:
+ insn->opcode = def->opcode;
+ use_pseudo(insn, def->src1, &insn->src1);
+ use_pseudo(insn, def->src2, &insn->src2);
+ remove_usage(src, &insn->src);
+ return REPEAT_CSE;
+
+ default:
+ break;
+ }
+ }
+
return 0;
simplify:
diff --git a/validation/optim/bool-simplify.c b/validation/optim/bool-simplify.c
index 05be11497..2014d344c 100644
--- a/validation/optim/bool-simplify.c
+++ b/validation/optim/bool-simplify.c
@@ -32,16 +32,14 @@ and_0:
and_1:
.L2:
<entry-point>
- setne.1 %r8 <- %arg1, $0
- cast.32 %r11 <- (1) %r8
+ setne.32 %r11 <- %arg1, $0
ret.32 %r11
or_0:
.L4:
<entry-point>
- setne.1 %r14 <- %arg1, $0
- cast.32 %r17 <- (1) %r14
+ setne.32 %r17 <- %arg1, $0
ret.32 %r17
--
2.12.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/6] avoid useless compare with zero
2017-04-12 19:33 [PATCH 0/6] fix boolean context Luc Van Oostenryck
2017-04-12 19:33 ` [PATCH 1/6] fix boolean context for OP_AND_BOOL & OP_OR_BOOL Luc Van Oostenryck
2017-04-12 19:33 ` [PATCH 2/6] simplify intermediate casts in boolean expressions Luc Van Oostenryck
@ 2017-04-12 19:33 ` Luc Van Oostenryck
2017-04-12 19:33 ` [PATCH 4/6] generate plain OP_{AND,OR} instead of OP_{AND,OR}_BOOL Luc Van Oostenryck
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Luc Van Oostenryck @ 2017-04-12 19:33 UTC (permalink / raw)
To: linux-sparse; +Cc: Christopher Li, Luc Van Oostenryck
The boolean operators '||' and '&&' need to have their operands
first compared against zero. However, this is not needed if the
operands is already a boolean, for example because it's already
the result of another previous such operation.
For example, the following expression:
int a, b, c;
... a || b || c ...
is linearized and simplified to:
setne.1 %r2 <- %arg1, $0
setne.1 %r4 <- %arg2, $0
or-bool.1 %r5 <- %r2, %r4
setne.1 %r7 <- %r5, $0
setne.1 %r9 <- %arg3, $0
or-bool.1 %r10 <- %r7, %r9
but the 3rd 'setne' is useless since %r5 is already a boolean value.
It can thus be further simplified to:
setne.1 %r2 <- %arg1, $0
setne.1 %r4 <- %arg2, $0
or-bool.1 %r5 <- %r2, %r4
setne.1 %r9 <- %arg3, $0
or-bool.1 %r10 <- %r5, %r9
Change this by removing such comparisons if the operand is
already a boolean (its size is 1).
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
simplify.c | 3 ++-
validation/optim/bool-context-fp.c | 6 ++----
validation/optim/bool-simplify2.c | 11 +++++++++++
3 files changed, 15 insertions(+), 5 deletions(-)
create mode 100644 validation/optim/bool-simplify2.c
diff --git a/simplify.c b/simplify.c
index 09d7ae056..30bbc9b99 100644
--- a/simplify.c
+++ b/simplify.c
@@ -462,7 +462,8 @@ static int simplify_seteq_setne(struct instruction *insn, long long value)
return REPEAT_CSE;
default:
- break;
+ if (!inverse && def->size == 1)
+ return replace_with_pseudo(insn, old);
}
return 0;
}
diff --git a/validation/optim/bool-context-fp.c b/validation/optim/bool-context-fp.c
index 6b3e8d181..2f15fe94d 100644
--- a/validation/optim/bool-context-fp.c
+++ b/validation/optim/bool-context-fp.c
@@ -54,8 +54,7 @@ bfior:
fcmpune.1 %r20 <- %arg1, %r19
fcmpune.1 %r23 <- %arg2, %r19
or-bool.1 %r24 <- %r23, %r20
- setne.1 %r26 <- %r24, $0
- ret.1 %r26
+ ret.1 %r24
ifior:
@@ -76,8 +75,7 @@ bfand:
fcmpune.1 %r39 <- %arg1, %r38
fcmpune.1 %r42 <- %arg2, %r38
and-bool.1 %r43 <- %r42, %r39
- setne.1 %r45 <- %r43, $0
- ret.1 %r45
+ ret.1 %r43
ifand:
diff --git a/validation/optim/bool-simplify2.c b/validation/optim/bool-simplify2.c
new file mode 100644
index 000000000..caa5af053
--- /dev/null
+++ b/validation/optim/bool-simplify2.c
@@ -0,0 +1,11 @@
+static int foo(int a, int b, int c)
+{
+ return a || b || c;
+}
+
+/*
+ * check-name: bool-simplify2
+ * check-command: test-linearize $file
+ * check-output-ignore
+ * check-output-pattern-3-times: setne\\.
+ */
--
2.12.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 4/6] generate plain OP_{AND,OR} instead of OP_{AND,OR}_BOOL
2017-04-12 19:33 [PATCH 0/6] fix boolean context Luc Van Oostenryck
` (2 preceding siblings ...)
2017-04-12 19:33 ` [PATCH 3/6] avoid useless compare with zero Luc Van Oostenryck
@ 2017-04-12 19:33 ` Luc Van Oostenryck
2017-04-12 19:33 ` [PATCH 5/6] llvm: no need to special-case OP_AND_BOOL and OP_OR_BOOL Luc Van Oostenryck
2017-04-12 19:33 ` [PATCH 6/6] remove OP_{AND,OR}_BOOL instructions Luc Van Oostenryck
5 siblings, 0 replies; 7+ messages in thread
From: Luc Van Oostenryck @ 2017-04-12 19:33 UTC (permalink / raw)
To: linux-sparse; +Cc: Christopher Li, Luc Van Oostenryck
Now that OP_AND_BOOL and OP_OR_BOOL are always given boolean
operands, they are just a special case of 1 bit OP_AND & OP_OR.
To avoid to have to repeat CSE, simplification patterns, ...
better to simply generate OP_AND & OP_OR instructions instead.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
linearize.c | 2 +-
validation/optim/bool-context-fp.c | 8 ++++----
validation/optim/bool-simplify.c | 24 ++++++++++++++++++++++++
3 files changed, 29 insertions(+), 5 deletions(-)
diff --git a/linearize.c b/linearize.c
index e730ab56f..e6b77ec01 100644
--- a/linearize.c
+++ b/linearize.c
@@ -1379,7 +1379,7 @@ static pseudo_t linearize_call_expression(struct entrypoint *ep, struct expressi
static pseudo_t linearize_binop_bool(struct entrypoint *ep, struct expression *expr)
{
pseudo_t src1, src2, dst;
- int op = (expr->op == SPECIAL_LOGICAL_OR) ? OP_OR_BOOL : OP_AND_BOOL;
+ int op = (expr->op == SPECIAL_LOGICAL_OR) ? OP_OR : OP_AND;
src1 = linearize_expression_to_bool(ep, expr->left);
src2 = linearize_expression_to_bool(ep, expr->right);
diff --git a/validation/optim/bool-context-fp.c b/validation/optim/bool-context-fp.c
index 2f15fe94d..3ce1574b9 100644
--- a/validation/optim/bool-context-fp.c
+++ b/validation/optim/bool-context-fp.c
@@ -53,7 +53,7 @@ bfior:
setfval.32 %r19 <- 0.000000
fcmpune.1 %r20 <- %arg1, %r19
fcmpune.1 %r23 <- %arg2, %r19
- or-bool.1 %r24 <- %r23, %r20
+ or.1 %r24 <- %r23, %r20
ret.1 %r24
@@ -63,7 +63,7 @@ ifior:
setfval.32 %r29 <- 0.000000
fcmpune.1 %r30 <- %arg1, %r29
fcmpune.1 %r33 <- %arg2, %r29
- or-bool.1 %r34 <- %r33, %r30
+ or.1 %r34 <- %r33, %r30
cast.32 %r35 <- (1) %r34
ret.32 %r35
@@ -74,7 +74,7 @@ bfand:
setfval.32 %r38 <- 0.000000
fcmpune.1 %r39 <- %arg1, %r38
fcmpune.1 %r42 <- %arg2, %r38
- and-bool.1 %r43 <- %r42, %r39
+ and.1 %r43 <- %r42, %r39
ret.1 %r43
@@ -84,7 +84,7 @@ ifand:
setfval.32 %r48 <- 0.000000
fcmpune.1 %r49 <- %arg1, %r48
fcmpune.1 %r52 <- %arg2, %r48
- and-bool.1 %r53 <- %r52, %r49
+ and.1 %r53 <- %r52, %r49
cast.32 %r54 <- (1) %r53
ret.32 %r54
diff --git a/validation/optim/bool-simplify.c b/validation/optim/bool-simplify.c
index 2014d344c..b872764ca 100644
--- a/validation/optim/bool-simplify.c
+++ b/validation/optim/bool-simplify.c
@@ -18,6 +18,17 @@ int or_1(int a)
return a || 1;
}
+// try again but with something true but != 1
+int and_2(int a)
+{
+ return a && 2;
+}
+
+int or_2(int a)
+{
+ return a || 2;
+}
+
/*
* check-name: bool-simplify
* check-command: test-linearize -Wno-decl $file
@@ -49,5 +60,18 @@ or_1:
ret.32 $1
+and_2:
+.L8:
+ <entry-point>
+ setne.32 %r29 <- %arg1, $0
+ ret.32 %r29
+
+
+or_2:
+.L10:
+ <entry-point>
+ ret.32 $1
+
+
* check-output-end
*/
--
2.12.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 5/6] llvm: no need to special-case OP_AND_BOOL and OP_OR_BOOL
2017-04-12 19:33 [PATCH 0/6] fix boolean context Luc Van Oostenryck
` (3 preceding siblings ...)
2017-04-12 19:33 ` [PATCH 4/6] generate plain OP_{AND,OR} instead of OP_{AND,OR}_BOOL Luc Van Oostenryck
@ 2017-04-12 19:33 ` Luc Van Oostenryck
2017-04-12 19:33 ` [PATCH 6/6] remove OP_{AND,OR}_BOOL instructions Luc Van Oostenryck
5 siblings, 0 replies; 7+ messages in thread
From: Luc Van Oostenryck @ 2017-04-12 19:33 UTC (permalink / raw)
To: linux-sparse; +Cc: Christopher Li, Luc Van Oostenryck
Now that OP_AND_BOOL and OP_OR_BOOL are not generated anymore,
we can remove the (special case) code that handled them.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
sparse-llvm.c | 24 ------------------------
1 file changed, 24 deletions(-)
diff --git a/sparse-llvm.c b/sparse-llvm.c
index da9f2ce25..b8acbd53d 100644
--- a/sparse-llvm.c
+++ b/sparse-llvm.c
@@ -609,30 +609,6 @@ static void output_op_binary(struct function *fn, struct instruction *insn)
assert(!is_float_type(insn->type));
target = LLVMBuildXor(fn->builder, lhs, rhs, target_name);
break;
- case OP_AND_BOOL: {
- LLVMValueRef lhs_nz, rhs_nz;
- LLVMTypeRef dst_type;
-
- lhs_nz = LLVMBuildIsNotNull(fn->builder, lhs, LLVMGetValueName(lhs));
- rhs_nz = LLVMBuildIsNotNull(fn->builder, rhs, LLVMGetValueName(rhs));
- target = LLVMBuildAnd(fn->builder, lhs_nz, rhs_nz, target_name);
-
- dst_type = insn_symbol_type(insn);
- target = LLVMBuildZExt(fn->builder, target, dst_type, target_name);
- break;
- }
- case OP_OR_BOOL: {
- LLVMValueRef lhs_nz, rhs_nz;
- LLVMTypeRef dst_type;
-
- lhs_nz = LLVMBuildIsNotNull(fn->builder, lhs, LLVMGetValueName(lhs));
- rhs_nz = LLVMBuildIsNotNull(fn->builder, rhs, LLVMGetValueName(rhs));
- target = LLVMBuildOr(fn->builder, lhs_nz, rhs_nz, target_name);
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 6/6] remove OP_{AND,OR}_BOOL instructions
2017-04-12 19:33 [PATCH 0/6] fix boolean context Luc Van Oostenryck
` (4 preceding siblings ...)
2017-04-12 19:33 ` [PATCH 5/6] llvm: no need to special-case OP_AND_BOOL and OP_OR_BOOL Luc Van Oostenryck
@ 2017-04-12 19:33 ` Luc Van Oostenryck
5 siblings, 0 replies; 7+ messages in thread
From: Luc Van Oostenryck @ 2017-04-12 19:33 UTC (permalink / raw)
To: linux-sparse; +Cc: Christopher Li, Luc Van Oostenryck
Now that OP_AND_BOOL and OP_OR_BOOL are not generated anymore
we can remove all related code & defines.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
cse.c | 4 +---
example.c | 3 ---
linearize.c | 2 --
linearize.h | 4 +---
simplify.c | 24 ------------------------
5 files changed, 2 insertions(+), 35 deletions(-)
diff --git a/cse.c b/cse.c
index cd1e8942c..0ea9b3241 100644
--- a/cse.c
+++ b/cse.c
@@ -61,8 +61,7 @@ static void clean_up_one_instruction(struct basic_block *bb, struct instruction
case OP_AND: case OP_OR:
/* Binary logical */
- case OP_XOR: case OP_AND_BOOL:
- case OP_OR_BOOL:
+ case OP_XOR:
/* Binary comparison */
case OP_SET_EQ: case OP_SET_NE:
@@ -192,7 +191,6 @@ static int insn_compare(const void *_i1, const void *_i2)
/* commutative binop */
case OP_ADD:
case OP_MULU: case OP_MULS:
- case OP_AND_BOOL: case OP_OR_BOOL:
case OP_AND: case OP_OR:
case OP_XOR:
case OP_SET_EQ: case OP_SET_NE:
diff --git a/example.c b/example.c
index 69e00b325..ca1077876 100644
--- a/example.c
+++ b/example.c
@@ -46,8 +46,6 @@ static const char *opcodes[] = {
[OP_AND] = "and",
[OP_OR] = "or",
[OP_XOR] = "xor",
- [OP_AND_BOOL] = "and-bool",
- [OP_OR_BOOL] = "or-bool",
/* Binary comparison */
[OP_SET_EQ] = "seteq",
@@ -1406,7 +1404,6 @@ static void generate_one_insn(struct instruction *insn, struct bb_state *state)
case OP_ADD: case OP_MULU: case OP_MULS:
case OP_AND: case OP_OR: case OP_XOR:
- case OP_AND_BOOL: case OP_OR_BOOL:
generate_commutative_binop(state, insn);
break;
diff --git a/linearize.c b/linearize.c
index e6b77ec01..8e8c99e4a 100644
--- a/linearize.c
+++ b/linearize.c
@@ -199,8 +199,6 @@ static const char *opcodes[] = {
[OP_AND] = "and",
[OP_OR] = "or",
[OP_XOR] = "xor",
- [OP_AND_BOOL] = "and-bool",
- [OP_OR_BOOL] = "or-bool",
/* Binary comparison */
[OP_SET_EQ] = "seteq",
diff --git a/linearize.h b/linearize.h
index 24cbcf94d..12a8fe3a7 100644
--- a/linearize.h
+++ b/linearize.h
@@ -175,9 +175,7 @@ enum opcode {
OP_AND,
OP_OR,
OP_XOR,
- OP_AND_BOOL,
- OP_OR_BOOL,
- OP_BINARY_END = OP_OR_BOOL,
+ OP_BINARY_END = OP_XOR,
/* floating-point comparison */
OP_FPCMP,
diff --git a/simplify.c b/simplify.c
index 30bbc9b99..f730dc8ce 100644
--- a/simplify.c
+++ b/simplify.c
@@ -475,11 +475,6 @@ static int simplify_constant_rightside(struct instruction *insn)
long long bits = sbit | (sbit - 1);
switch (insn->opcode) {
- case OP_OR_BOOL:
- if (value == 1)
- return replace_with_pseudo(insn, insn->src2);
- goto case_neutral_zero;
-
case OP_OR:
if ((value & bits) == bits)
return replace_with_pseudo(insn, insn->src2);
@@ -518,10 +513,6 @@ static int simplify_constant_rightside(struct instruction *insn)
case OP_MULU: case OP_MULS:
return simplify_mul_div(insn, value);
- case OP_AND_BOOL:
- if (value == 1)
- return replace_with_pseudo(insn, insn->src1);
- /* Fall through */
case OP_AND:
if ((value & bits) == bits)
return replace_with_pseudo(insn, insn->src1);
@@ -631,13 +622,6 @@ static int simplify_constant_binop(struct instruction *insn)
case OP_XOR:
res = left ^ right;
break;
- case OP_AND_BOOL:
- res = left && right;
- break;
- case OP_OR_BOOL:
- res = left || right;
- break;
-
/* Binary comparison */
case OP_SET_EQ:
res = left == right;
@@ -701,13 +685,6 @@ static int simplify_binop_same_args(struct instruction *insn, pseudo_t arg)
case OP_OR:
return replace_with_pseudo(insn, arg);
- case OP_AND_BOOL:
- case OP_OR_BOOL:
- remove_usage(arg, &insn->src2);
- insn->src2 = value_pseudo(0);
- insn->opcode = OP_SET_NE;
- return REPEAT_CSE;
^ permalink raw reply related [flat|nested] 7+ messages in thread