This simple patch extends the min_value/max_value match to vector integer types.
Using uniform_integer_cst_p makes this easy.
OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.
The testcases pr110915-*.c are the same as pr88784-*.c except using vector
types instead.
PR tree-optimization/110915
gcc/ChangeLog:
* match.pd (min_value, max_value): Extend to vector constants.
gcc/testsuite/ChangeLog:
* gcc.dg/pr110915-1.c: New test.
* gcc.dg/pr110915-10.c: New test.
* gcc.dg/pr110915-11.c: New test.
* gcc.dg/pr110915-12.c: New test.
* gcc.dg/pr110915-2.c: New test.
* gcc.dg/pr110915-3.c: New test.
* gcc.dg/pr110915-4.c: New test.
* gcc.dg/pr110915-5.c: New test.
* gcc.dg/pr110915-6.c: New test.
* gcc.dg/pr110915-7.c: New test.
* gcc.dg/pr110915-8.c: New test.
* gcc.dg/pr110915-9.c: New test.
& (bitpos / BITS_PER_UNIT))); }))))
(match min_value
- INTEGER_CST
- (if ((INTEGRAL_TYPE_P (type)
- || POINTER_TYPE_P(type))
- && wi::eq_p (wi::to_wide (t), wi::min_value (type)))))
+ uniform_integer_cst_p
+ (with {
+ tree int_cst = uniform_integer_cst_p (t);
+ tree inner_type = TREE_TYPE (int_cst);
+ }
+ (if ((INTEGRAL_TYPE_P (inner_type)
+ || POINTER_TYPE_P (inner_type))
+ && wi::eq_p (wi::to_wide (int_cst), wi::min_value (inner_type))))))
(match max_value
- INTEGER_CST
- (if ((INTEGRAL_TYPE_P (type)
- || POINTER_TYPE_P(type))
- && wi::eq_p (wi::to_wide (t), wi::max_value (type)))))
+ uniform_integer_cst_p
+ (with {
+ tree int_cst = uniform_integer_cst_p (t);
+ tree itype = TREE_TYPE (int_cst);
+ }
+ (if ((INTEGRAL_TYPE_P (itype)
+ || POINTER_TYPE_P (itype))
+ && wi::eq_p (wi::to_wide (int_cst), wi::max_value (itype))))))
/* x > y && x != XXX_MIN --> x > y
x > y && x == XXX_MIN --> false . */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-ifcombine" } */
+#define vector __attribute__((vector_size(sizeof(unsigned)*2)))
+
+#include <limits.h>
+
+vector signed and1(vector unsigned x, vector unsigned y)
+{
+ /* (x > y) & (x != 0) --> x > y */
+ return (x > y) & (x != 0);
+}
+
+vector signed and2(vector unsigned x, vector unsigned y)
+{
+ /* (x < y) & (x != UINT_MAX) --> x < y */
+ return (x < y) & (x != UINT_MAX);
+}
+
+vector signed and3(vector signed x, vector signed y)
+{
+ /* (x > y) & (x != INT_MIN) --> x > y */
+ return (x > y) & (x != INT_MIN);
+}
+
+vector signed and4(vector signed x, vector signed y)
+{
+ /* (x < y) & (x != INT_MAX) --> x < y */
+ return (x < y) & (x != INT_MAX);
+}
+
+/* { dg-final { scan-tree-dump-not " != " "ifcombine" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+#define vector __attribute__((vector_size(sizeof(unsigned)*2)))
+
+#include <limits.h>
+
+vector unsigned or1(vector unsigned x, vector unsigned y)
+{
+ /* (x <= y) | (x != 0)) --> true */
+ return (x <= y) | (x != 0);
+}
+
+vector unsigned or2(vector unsigned x, vector unsigned y)
+{
+ /* (x >= y) | (x != UINT_MAX) --> true */
+ return (x >= y) | (x != UINT_MAX);
+}
+
+vector signed or3(vector signed x, vector signed y)
+{
+ /* (x <= y) | (x != INT_MIN) --> true */
+ return (x <= y) | (x != INT_MIN);
+}
+
+vector signed or4(vector signed x, vector signed y)
+{
+ /* (x >= y) | (x != INT_MAX) --> true */
+ return (x >= y) | (x != INT_MAX);
+}
+
+/* { dg-final { scan-tree-dump-not " != " "optimized" } } */
+/* { dg-final { scan-tree-dump-not " <= " "optimized" } } */
+/* { dg-final { scan-tree-dump-not " >= " "optimized" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-ifcombine" } */
+#define vector __attribute__((vector_size(sizeof(unsigned)*2)))
+
+#include <limits.h>
+
+vector unsigned or1(vector unsigned x, vector unsigned y)
+{
+ /* (x <= y) | (x == 0) --> x <= y */
+ return (x <= y) | (x == 0);
+}
+
+vector unsigned or2(vector unsigned x, vector unsigned y)
+{
+ /* (x >= y) | (x == UINT_MAX) --> x >= y */
+ return (x >= y) | (x == UINT_MAX);
+}
+
+vector signed or3(vector signed x, vector signed y)
+{
+ /* (x <= y) | (x == INT_MIN) --> x <= y */
+ return (x <= y) | (x == INT_MIN);
+}
+
+vector signed or4(vector signed x, vector signed y)
+{
+ /* (x >= y) | (x == INT_MAX) --> x >= y */
+ return (x >= y) | (x == INT_MAX);
+}
+
+/* { dg-final { scan-tree-dump-not " == " "ifcombine" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-dce3" } */
+#define vector __attribute__((vector_size(sizeof(unsigned)*2)))
+
+#include <limits.h>
+
+vector unsigned or1(vector unsigned x, vector unsigned y)
+{
+ /* (x <= y) | (x == 0) --> x <= y */
+ return (x <= y) | (x == 0);
+}
+
+vector unsigned or2(vector unsigned x, vector unsigned y)
+{
+ /* (x >= y) | (x == UINT_MAX) --> x >= y */
+ return (x >= y) | (x == UINT_MAX);
+}
+
+vector signed or3(vector signed x, vector signed y)
+{
+ /* (x <= y) | (x == INT_MIN) --> x <= y */
+ return (x <= y) | (x == INT_MIN);
+}
+
+vector signed or4(vector signed x, vector signed y)
+{
+ /* (x >= y) | (x == INT_MAX) --> x >= y */
+ return (x >= y) | (x == INT_MAX);
+}
+
+/* { dg-final { scan-tree-dump-not " == " "dce3" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+#define vector __attribute__((vector_size(sizeof(unsigned)*2)))
+
+#include <limits.h>
+
+vector signed and1(vector unsigned x, vector unsigned y)
+{
+ /* (x > y) & (x != 0) --> x > y */
+ return (x > y) & (x != 0);
+}
+
+vector signed and2(vector unsigned x, vector unsigned y)
+{
+ /* (x < y) & (x != UINT_MAX) --> x < y */
+ return (x < y) & (x != UINT_MAX);
+}
+
+vector signed and3(vector signed x, vector signed y)
+{
+ /* (x > y) & (x != INT_MIN) --> x > y */
+ return (x > y) & (x != INT_MIN);
+}
+
+vector signed and4(vector signed x, vector signed y)
+{
+ /* (x < y) & (x != INT_MAX) --> x < y */
+ return (x < y) & (x != INT_MAX);
+}
+
+/* { dg-final { scan-tree-dump-not " != " "optimized" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-ifcombine" } */
+#define vector __attribute__((vector_size(sizeof(unsigned)*2)))
+
+#include <limits.h>
+
+vector signed and1(vector unsigned x, vector unsigned y)
+{
+ /* (x > y) & (x == 0) --> false */
+ return (x > y) & (x == 0);
+}
+
+vector signed and2(vector unsigned x, vector unsigned y)
+{
+ /* (x < y) & (x == UINT_MAX) --> false */
+ return (x < y) & (x == UINT_MAX);
+}
+
+vector signed and3(vector signed x, vector signed y)
+{
+ /* (x > y) & (x == INT_MIN) --> false */
+ return (x > y) & (x == INT_MIN);
+}
+
+vector signed and4(vector signed x, vector signed y)
+{
+ /* (x < y) & (x == INT_MAX) --> false */
+ return (x < y) & (x == INT_MAX);
+}
+
+/* { dg-final { scan-tree-dump-not " == " "ifcombine" } } */
+/* { dg-final { scan-tree-dump-not " > " "ifcombine" } } */
+/* { dg-final { scan-tree-dump-not " < " "ifcombine" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+#define vector __attribute__((vector_size(sizeof(unsigned)*2)))
+
+#include <limits.h>
+
+vector signed and1(vector unsigned x, vector unsigned y)
+{
+ /* (x > y) & (x == 0) --> false */
+ return (x > y) & (x == 0);
+}
+
+vector signed and2(vector unsigned x, vector unsigned y)
+{
+ /* (x < y) & (x == UINT_MAX) --> false */
+ return (x < y) & (x == UINT_MAX);
+}
+
+vector signed and3(vector signed x, vector signed y)
+{
+ /* (x > y) & (x == INT_MIN) --> false */
+ return (x > y) & (x == INT_MIN);
+}
+
+vector signed and4(vector signed x, vector signed y)
+{
+ /* (x < y) & (x == INT_MAX) --> false */
+ return (x < y) & (x == INT_MAX);
+}
+
+/* { dg-final { scan-tree-dump-not " == " "optimized" } } */
+/* { dg-final { scan-tree-dump-not " > " "optimized" } } */
+/* { dg-final { scan-tree-dump-not " < " "optimized" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-ifcombine" } */
+#define vector __attribute__((vector_size(sizeof(unsigned)*2)))
+
+#include <limits.h>
+
+vector signed and1(vector unsigned x, vector unsigned y)
+{
+ /* (x <= y) & (x == 0) --> x == 0 */
+ return (x <= y) & (x == 0);
+}
+
+vector signed and2(vector unsigned x, vector unsigned y)
+{
+ /* (x >= y) & (x == UINT_MAX) --> x == UINT_MAX */
+ return (x >= y) & (x == UINT_MAX);
+}
+
+vector signed and3(vector signed x, vector signed y)
+{
+ /* (x <= y) & (x == INT_MIN) --> x == INT_MIN */
+ return (x <= y) & (x == INT_MIN);
+}
+
+vector signed and4(vector signed x, vector signed y)
+{
+ /* (x >= y) & (x == INT_MAX) --> x == INT_MAX */
+ return (x >= y) & (x == INT_MAX);
+}
+
+/* { dg-final { scan-tree-dump-not " <= " "ifcombine" } } */
+/* { dg-final { scan-tree-dump-not " >= " "ifcombine" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+#define vector __attribute__((vector_size(sizeof(unsigned)*2)))
+
+#include <limits.h>
+
+vector signed and1(vector unsigned x, vector unsigned y)
+{
+ /* (x <= y) & (x == 0) --> x == 0 */
+ return (x <= y) & (x == 0);
+}
+
+vector signed and2(vector unsigned x, vector unsigned y)
+{
+ /* (x >= y) & (x == UINT_MAX) --> x == UINT_MAX */
+ return (x >= y) & (x == UINT_MAX);
+}
+
+vector signed and3(vector signed x, vector signed y)
+{
+ /* (x <= y) & (x == INT_MIN) --> x == INT_MIN */
+ return (x <= y) & (x == INT_MIN);
+}
+
+vector signed and4(vector signed x, vector signed y)
+{
+ /* (x >= y) & (x == INT_MAX) --> x == INT_MAX */
+ return (x >= y) & (x == INT_MAX);
+}
+
+/* { dg-final { scan-tree-dump-not " <= " "optimized" } } */
+/* { dg-final { scan-tree-dump-not " >= " "optimized" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-ifcombine" } */
+#define vector __attribute__((vector_size(sizeof(unsigned)*2)))
+
+#include <limits.h>
+
+vector signed or1(vector unsigned x, vector unsigned y)
+{
+ /* (x > y) | (x != 0) --> x != 0 */
+ return (x > y) | (x != 0);
+}
+
+vector signed or2(vector unsigned x, vector unsigned y)
+{
+ /* (x < y) | (x != UINT_MAX) --> x != UINT_MAX */
+ return (x < y) | (x != UINT_MAX);
+}
+
+vector signed or3(vector signed x, vector signed y)
+{
+ /* (x > y) | (x != INT_MIN) --> x != INT_MIN */
+ return (x > y) | (x != INT_MIN);
+}
+
+vector signed or4(vector signed x, vector signed y)
+{
+ /* (x < y) | (x != INT_MAX) --> x != INT_MAX */
+ return (x < y) | (x != INT_MAX);
+}
+
+/* { dg-final { scan-tree-dump-not " > " "ifcombine" } } */
+/* { dg-final { scan-tree-dump-not " < " "ifcombine" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+#define vector __attribute__((vector_size(sizeof(unsigned)*2)))
+
+#include <limits.h>
+
+vector signed or1(vector unsigned x, vector unsigned y)
+{
+ /* (x > y) | (x != 0) --> x != 0 */
+ return (x > y) | (x != 0);
+}
+
+vector signed or2(vector unsigned x, vector unsigned y)
+{
+ /* (x < y) | (x != UINT_MAX) --> x != UINT_MAX */
+ return (x < y) | (x != UINT_MAX);
+}
+
+vector signed or3(vector signed x, vector signed y)
+{
+ /* (x > y) | (x != INT_MIN) --> x != INT_MIN */
+ return (x > y) | (x != INT_MIN);
+}
+
+vector signed or4(vector signed x, vector signed y)
+{
+ /* (x < y) | (x != INT_MAX) --> x != INT_MAX */
+ return (x < y) | (x != INT_MAX);
+}
+
+/* { dg-final { scan-tree-dump-not " > " "optimized" } } */
+/* { dg-final { scan-tree-dump-not " < " "optimized" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-ifcombine" } */
+#define vector __attribute__((vector_size(sizeof(unsigned)*2)))
+
+#include <limits.h>
+
+vector signed or1(vector unsigned x, vector unsigned y)
+{
+ /* (x <= y) | (x != 0) --> true */
+ return (x <= y) | (x != 0);
+}
+
+vector signed or2(vector unsigned x, vector unsigned y)
+{
+ /* (x >= y) | (x != UINT_MAX) --> true */
+ return (x >= y) | (x != UINT_MAX);
+}
+
+vector signed or3(vector signed x, vector signed y)
+{
+ /* (x <= y) | (x != INT_MIN) --> true */
+ return (x <= y) | (x != INT_MIN);
+}
+
+vector signed or4(vector signed x, vector signed y)
+{
+ /* (x >= y) | (x != INT_MAX) --> true */
+ return (x >= y) | (x != INT_MAX);
+}
+
+/* { dg-final { scan-tree-dump-not " != " "ifcombine" } } */
+/* { dg-final { scan-tree-dump-not " <= " "ifcombine" } } */
+/* { dg-final { scan-tree-dump-not " >= " "ifcombine" } } */