Issue 128488
Summary LLVM fails to recognize the same condition sometimes
Labels missed-optimization
Assignees
Reporter philnik777
    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

_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to