public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "pinskia at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/110598] [14 Regression] wrong code on llvm-14.0.6 due to memcmp being miscompiled
Date: Sat, 08 Jul 2023 17:32:41 +0000	[thread overview]
Message-ID: <bug-110598-4-5c1hCtSzLv@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-110598-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110598

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2023-07-08
             Status|UNCONFIRMED                 |NEW
   Target Milestone|---                         |14.0
           Keywords|                            |wrong-code
            Summary|[14 Regression] wrong code  |[14 Regression] wrong code
                   |on llvm-14.0.6              |on llvm-14.0.6 due to
                   |                            |memcmp being miscompiled
     Ever confirmed|0                           |1
          Component|c++                         |target

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed looks like a target issue dealing with memcmp.
Take:
```

// $ cat bug.cpp
#include <iterator>

typedef unsigned long long u64;

const unsigned MAX_SUBTARGET_WORDS = 4;

[[gnu::noipa]]
int notequal(const void *a, const void *b)
{
        return __builtin_memcmp(a,b,MAX_SUBTARGET_WORDS*sizeof(u64)) != 0;
}

struct FeatureBitset {
  u64 Bits[MAX_SUBTARGET_WORDS] = {0, 0, 0, 0};

  constexpr FeatureBitset() = default;
  constexpr FeatureBitset(std::initializer_list<unsigned> Init) {
    for (auto I : Init) {
      Bits[I] = 1;
    }
  }

  constexpr FeatureBitset operator&(const FeatureBitset &RHS) const {
    FeatureBitset Result = *this;
    for (unsigned I = 0, E = MAX_SUBTARGET_WORDS; I != E; ++I) {
      Result.Bits[I] &= RHS.Bits[I];
    }
    return Result;
  }

  bool operator!=(const FeatureBitset &RHS) const {
      return notequal(Bits, RHS.Bits);
  }
};

static constexpr const FeatureBitset TargetFeatures = { 0, 0, 0, 0, };

__attribute__((noipa))
bool is_eq_buggy (const FeatureBitset & lf, const FeatureBitset & rf) {
  if ((lf & TargetFeatures) != (rf & TargetFeatures))
    return false;
  return true;
}

__attribute__((noipa))
void bug(void) {
    FeatureBitset lf, rf;
    lf.Bits[0] = rf.Bits[0] = 1;
    lf.Bits[1] = rf.Bits[1] = 1;
    lf.Bits[2] = rf.Bits[2] = 1;
    lf.Bits[3] = rf.Bits[3] = 1;

    bool r = is_eq_buggy (lf, rf);
    if (!r) __builtin_trap();
}

__attribute__((noipa))
int main(void) {
    bug();
}
```

The above is not miscompiled but once the gnu::noipa on the notequal is
removed, it is.

  reply	other threads:[~2023-07-08 17:32 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-08 17:00 [Bug c++/110598] New: [14 Regression] wrong code on llvm-14.0.6 slyfox at gcc dot gnu.org
2023-07-08 17:32 ` pinskia at gcc dot gnu.org [this message]
2023-07-08 17:41 ` [Bug target/110598] [14 Regression] wrong code on llvm-14.0.6 due to memcmp being miscompiled pinskia at gcc dot gnu.org
2023-07-08 20:31 ` slyfox at gcc dot gnu.org
2023-07-09 22:34 ` roger at nextmovesoftware dot com
2023-07-12 13:13 ` cvs-commit at gcc dot gnu.org
2023-07-12 16:15 ` slyfox at gcc dot gnu.org
2023-07-12 19:42 ` roger at nextmovesoftware dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-110598-4-5c1hCtSzLv@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).