aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2024-03-20 10:55:07 +0100
committerJakub Jelinek <jakub@redhat.com>2024-03-20 10:55:07 +0100
commit456e10f28b36aa417e0db145556831c4f979fbd7 (patch)
treedb543e0d5f323802d4c94a47044019783f3c9c84
parent4c276896d646c2dbc8047fd81d6e65f8c5ecf01d (diff)
downloadgcc-456e10f28b36aa417e0db145556831c4f979fbd7.zip
gcc-456e10f28b36aa417e0db145556831c4f979fbd7.tar.gz
gcc-456e10f28b36aa417e0db145556831c4f979fbd7.tar.bz2
bitint: Fix handling of conditional bitfield loads [PR114365]
For the m_var_msb (aka left shift) case of large/huge _BitInt bitfield loads handle_load adds a PHI node, but I forgot to actually update the temporary the code later on uses, so the PHI result was unused and the code incorrectly used something that wasn't valid SSA form. In particular, we emitted if (_29 != 2) goto <bb 4>; [80.00%] else goto <bb 5>; [20.00%] <bb 4> [local count: 1073741824]: _33 = VIEW_CONVERT_EXPR<unsigned long[3]>(s.D.2771)[_31]; <bb 5> [local count: 1073741824]: # _34 = PHI <_33(4), 0(3)> _35 = _32 >> 31; _36 = _33 << 33; _37 = _36 | _35; _38 = _37 << _19; where instead of _33 the _36 def stmt should be using _34. Fixed thusly. 2024-03-20 Jakub Jelinek <jakub@redhat.com> PR tree-optimization/114365 * gimple-lower-bitint.cc (bitint_large_huge::handle_load): When adding a PHI node, set iv2 to its result afterwards. * gcc.dg/bitint-102.c: New test.
-rw-r--r--gcc/gimple-lower-bitint.cc1
-rw-r--r--gcc/testsuite/gcc.dg/bitint-102.c18
2 files changed, 19 insertions, 0 deletions
diff --git a/gcc/gimple-lower-bitint.cc b/gcc/gimple-lower-bitint.cc
index 40d814e..1ce13ca 100644
--- a/gcc/gimple-lower-bitint.cc
+++ b/gcc/gimple-lower-bitint.cc
@@ -2026,6 +2026,7 @@ bitint_large_huge::handle_load (gimple *stmt, tree idx)
add_phi_arg (phi, build_zero_cst (m_limb_type),
edge_false, UNKNOWN_LOCATION);
m_gsi = gsi_after_labels (edge_true->dest);
+ iv2 = iv3;
}
}
g = gimple_build_assign (make_ssa_name (m_limb_type), RSHIFT_EXPR,
diff --git a/gcc/testsuite/gcc.dg/bitint-102.c b/gcc/testsuite/gcc.dg/bitint-102.c
new file mode 100644
index 0000000..9f9861e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/bitint-102.c
@@ -0,0 +1,18 @@
+/* PR tree-optimization/114365 */
+/* { dg-do compile { target bitint } } */
+/* { dg-options "-std=c23 -O2" } */
+
+struct S {
+ int : 31;
+#if __BITINT_MAXWIDTH__ >= 129
+ _BitInt(129) b : 129;
+#else
+ _BitInt(63) b : 63;
+#endif
+} s;
+
+void
+foo (int a)
+{
+ s.b <<= a;
+}