On Mon, Feb 8, 2016 at 10:16 AM, Senthil Kumar Selvaraj
<senthil_kumar.selva...@atmel.com> wrote:
>
> Hurugalawadi, Naveen writes:
>
>> Hi,
>>
>> Please find attached the patch that performs optimization on unsigned values.
>>
>> Original fold-const part implemented in match.pd.
>>
>> Please review the patch and let us know if it's OK?
>>
>> Regression Tested on X86_64 with no regressions.
>>
>> Thanks,
>> Naveen
>>
>> ChangeLog:
>> * match.pd (cmp (convert (bit_not @0)) INTEGER_CST@1): New Simplifier.
>>
>> Testsuite/ChangeLog:
>> * gcc.dg/pr31531.c : New testcase.
>
> Could you please add dg-require-effective-target int32 to the test to
> avoid breaking targets with smaller ints (right shift by 31 bits)?

+/* Fold ((CAST)~X) op C as ((CAST)X) op' ~C, where op' is the
+   swapped comparison.  */
+(for cmp (tcc_comparison)
+     scmp (swapped_tcc_comparison)
+ (simplify
+  (cmp (convert (bit_not @0)) INTEGER_CST@1)
+  (if (TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (@0))
+       && TYPE_PRECISION (TREE_TYPE (@0)) == TYPE_PRECISION (TREE_TYPE (@1)))
+   (with { tree cst = fold_convert (TREE_TYPE (@0), @1); }
+    (scmp @0 (bit_not { cst; }))))))

I fail to see how this pattern is a good fit for the testcase, can you
try explaining?
I'm wondering that you require 'type's precision (a bool!) to be equal
to that of @0.
I'm also failing to see why you can't enhance the existing

/* 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)
  (if (single_use (@2)
       && (TREE_CODE (@1) == INTEGER_CST || TREE_CODE (@1) == VECTOR_CST))
   (scmp @0 (bit_not @1)))))

Thanks,
Richard.

> Regards
> Senthil

Reply via email to