@@ -453,6 +453,8 @@ static int simplify_seteq_setne(struct instruction *insn, long long value)
static int simplify_constant_rightside(struct instruction *insn)
{
long long value = insn->src2->value;
+ long long sbit = 1ULL << (insn->size - 1);
+ long long bits = sbit | (sbit - 1);
switch (insn->opcode) {
case OP_OR_BOOL:
@@ -460,6 +462,11 @@ static int simplify_constant_rightside(struct instruction *insn)
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);
+ goto case_neutral_zero;
+
case OP_SUB:
if (value) {
insn->opcode = OP_ADD;
@@ -468,7 +475,7 @@ static int simplify_constant_rightside(struct instruction *insn)
}
/* Fall through */
case OP_ADD:
- case OP_OR: case OP_XOR:
+ case OP_XOR:
case OP_SHL:
case OP_LSR:
case_neutral_zero:
@@ -492,6 +499,8 @@ static int simplify_constant_rightside(struct instruction *insn)
return replace_with_pseudo(insn, insn->src1);
/* Fall through */
case OP_AND:
+ if ((value & bits) == bits)
+ return replace_with_pseudo(insn, insn->src1);
if (!value)
return replace_with_pseudo(insn, insn->src2);
return 0;
new file mode 100644
@@ -0,0 +1,22 @@
+int or_not0(int a) { return a | ~0; }
+int and_not0(int a) { return a & ~0; }
+
+/*
+ * check-name: bool-not-zero
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-start
+or_not0:
+.L0:
+ <entry-point>
+ ret.32 $0xffffffff
+
+
+and_not0:
+.L2:
+ <entry-point>
+ ret.32 %arg1
+
+
+ * check-output-end
+ */
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> --- simplify.c | 11 ++++++++++- validation/optim/bool-not-zero.c | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 validation/optim/bool-not-zero.c