<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/128488>128488</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            LLVM fails to recognize the same condition sometimes
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            missed-optimization
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          philnik777
      </td>
    </tr>
</table>

<pre>
    In libc++ we have the following string representation:
```c++
namespace std {

using size_t = __SIZE_TYPE__;

struct string {
  union {
    struct {
      size_t __is_long_ : 1;
      size_t __long_cap_ : 63;
      size_t __long_size_;
      char* __long_data_;
    };
    struct {
 unsigned char : 1;
      unsigned char __short_size_ : 7;
      char __short_data_[23];
    };
  };

  void __set_size(size_t __s) {
    if (__is_long_) {
      __long_size_ = __s;
    } else {
      __short_size_ = __s;
      __is_long_ = false;
    }
  }

  char* __get_pointer() {
 return __is_long_ ? __long_data_ : &__short_data_[0];
  }
};
}

auto test1(std::string& str, std::size_t size) {
  str.__set_size(size);
 return str.__get_pointer();
}

auto test2(std::string& str, std::size_t size) {
  auto __ptr = str.__get_pointer();
  str.__set_size(size);
 return __ptr;
}
```

I've noticed recently that the code generated for the two functions above are significantly different, even though they are semantically equivalent. For some reason `test1` generates significantly worse code than `test2`. https://godbolt.org/z/15czrP69d

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJykVV2L6zYQ_TXKy7DBluPYefBDtrmBhVu40FJoX4xijW21suRK4yybX19kOx_O9pbChYAjzcyZc87YkvBeNQaxYOkrSw8rMVBrXdG3Shv1V5Zlq5OVH8WbAa1OFeOvjL_CO0IrzgjUItRWa_uuTAOeXHg47B16NCRIWcOSPYv2bBtNvxmBRXsjOvS9qBA8SWBZ2GPRfvAjlLpgScCSA5TlL29_fCl__f3bl7JkyZzmyQ0VXVtO1QCDUdbcVgBz1n0DrshlqXyprWlKYMke4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