[1/7] libstdc++: Ensure __builtin_constant_p isn't lost on the way

Message ID 21793652.EfDdHjke4D@minbar
State Accepted
Headers
Series Work on PR108030 and several simd bugfixes and testsuite improvements |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Matthias Kretz Feb. 15, 2023, 8:49 p.m. UTC
  The more expensive code path should only be taken if it can be optimized
away.

Signed-off-by: Matthias Kretz <m.kretz@gsi.de>

libstdc++-v3/ChangeLog:

	* include/experimental/bits/simd.h
	(_SimdWrapper::_M_is_constprop_none_of)
	(_SimdWrapper::_M_is_constprop_all_of): Return false unless the
	computed result still satisfies __builtin_constant_p.
---
 libstdc++-v3/include/experimental/bits/simd.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)


--
──────────────────────────────────────────────────────────────────────────
 Dr. Matthias Kretz                           https://mattkretz.github.io
 GSI Helmholtz Centre for Heavy Ion Research               https://gsi.de
 stdₓ::simd
──────────────────────────────────────────────────────────────────────────
  

Comments

Jonathan Wakely Feb. 15, 2023, 11:20 p.m. UTC | #1
On Wed, 15 Feb 2023 at 20:49, Matthias Kretz via Libstdc++
<libstdc++@gcc.gnu.org> wrote:
>
>
>
> The more expensive code path should only be taken if it can be optimized
> away.
>
> Signed-off-by: Matthias Kretz <m.kretz@gsi.de>
>
> libstdc++-v3/ChangeLog:
>
>         * include/experimental/bits/simd.h
>         (_SimdWrapper::_M_is_constprop_none_of)
>         (_SimdWrapper::_M_is_constprop_all_of): Return false unless the
>         computed result still satisfies __builtin_constant_p.

OK for trunk/12/11.
  

Patch

diff --git a/libstdc++-v3/include/experimental/bits/simd.h b/libstdc++-v3/include/experimental/bits/simd.h
index e76f4781fa6..3de966bbf22 100644
--- a/libstdc++-v3/include/experimental/bits/simd.h
+++ b/libstdc++-v3/include/experimental/bits/simd.h
@@ -2673,7 +2673,8 @@  template <typename _Tp, size_t _Width>
 	  else
 	    __execute_n_times<_Width>(
 	      [&](auto __i) { __r &= _M_data[__i.value] == _Tp(); });
-	  return __r;
+	  if (__builtin_constant_p(__r))
+	    return __r;
 	}
       return false;
     }
@@ -2693,7 +2694,8 @@  template <typename _Tp, size_t _Width>
 	  else
 	    __execute_n_times<_Width>(
 	      [&](auto __i) { __r &= _M_data[__i.value] == ~_Tp(); });
-	  return __r;
+	  if (__builtin_constant_p(__r))
+	    return __r;
 	}
       return false;
     }