/* Fold ~X op ~Y as Y op X. */
(for cmp (simple_comparison)
(simplify
- (cmp (bit_not@2 @0) (bit_not@3 @1))
+ (cmp (nop_convert1?@4 (bit_not@2 @0)) (nop_convert2? (bit_not@3 @1)))
(if (single_use (@2) && single_use (@3))
- (cmp @1 @0))))
+ (with { tree otype = TREE_TYPE (@4); }
+ (cmp (convert:otype @1) (convert:otype @0))))))
/* Fold ~X op C as X op' ~C, where op' is the swapped comparison. */
(for cmp (simple_comparison)
scmp (swapped_simple_comparison)
(simplify
- (cmp (bit_not@2 @0) CONSTANT_CLASS_P@1)
+ (cmp (nop_convert? (bit_not@2 @0)) CONSTANT_CLASS_P@1)
(if (single_use (@2)
&& (TREE_CODE (@1) == INTEGER_CST || TREE_CODE (@1) == VECTOR_CST))
- (scmp @0 (bit_not @1)))))
+ (with { tree otype = TREE_TYPE (@1); }
+ (scmp (convert:otype @0) (bit_not @1))))))
(for cmp (simple_comparison)
(simplify
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+/* PR tree-optimization/31531 */
+
+int f(int a)
+{
+ int b = ~a;
+ return b<0;
+}
+
+
+int f1(unsigned a)
+{
+ int b = ~a;
+ return b<0;
+}
+/* We should convert the above two functions from b <0 to ((int)a) >= 0. */
+/* { dg-final { scan-tree-dump-times ">= 0" 2 "optimized"} } */
+/* { dg-final { scan-tree-dump-times "~" 0 "optimized"} } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+/* PR tree-optimization/31531 */
+
+int f0(unsigned x, unsigned t)
+{
+ x = ~x;
+ t = ~t;
+ int xx = x;
+ int tt = t;
+ return tt < xx;
+}
+
+int f1(unsigned x, int t)
+{
+ x = ~x;
+ t = ~t;
+ int xx = x;
+ int tt = t;
+ return tt < xx;
+}
+
+int f2(int x, unsigned t)
+{
+ x = ~x;
+ t = ~t;
+ int xx = x;
+ int tt = t;
+ return tt < xx;
+}
+
+
+/* We should be able to remove all ~ from the above functions. */
+/* { dg-final { scan-tree-dump-times "~" 0 "optimized"} } */