Bug 108209 - goof in genmatch.cc:commutative_op
Summary: goof in genmatch.cc:commutative_op
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 13.0
: P3 normal
Target Milestone: ---
Assignee: Richard Biener
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-12-23 13:30 UTC by Alexander Monakov
Modified: 2023-01-09 14:08 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2023-01-09 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Monakov 2022-12-23 13:30:53 UTC
It pretends that define_operator_list is commutative when its first member is NOT commutative:

  if (user_id *uid = dyn_cast<user_id *> (id))
    {
      int res = commutative_op (uid->substitutes[0]);
      if (res < 0)
        return 0;
      for (unsigned i = 1; i < uid->substitutes.length (); ++i)
        if (res != commutative_op (uid->substitutes[i]))
          return -1;
      return res;
    }

The first 'return 0' should be 'return -1' instead.
Comment 1 Alexander Monakov 2022-12-23 17:56:58 UTC
Keeping notes as I go...

Duplicated checks for 'op0' in lower_for are duplicated.
Comment 2 Richard Biener 2023-01-09 13:27:19 UTC
Mine.
Comment 3 GCC Commits 2023-01-09 14:08:03 UTC
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:46034c46f82dec169fe7fc7c2d82d8321d9a9512

commit r13-5068-g46034c46f82dec169fe7fc7c2d82d8321d9a9512
Author: Richard Biener <rguenther@suse.de>
Date:   Mon Jan 9 14:28:03 2023 +0100

    middle-end/108209 - typo in genmatch.cc:commutative_op
    
    The early out for user-id handling indicated commutative
    rather than not commutative.
    
            PR middle-end/108209
            * genmatch.cc (commutative_op): Fix return value for
            user-id with non-commutative first replacement.
Comment 4 Richard Biener 2023-01-09 14:08:16 UTC
Fixed.