[gcc(refs/users/aoliva/heads/testme)] ifcombine: simplify and check for build error

2024-12-01 Thread Alexandre Oliva via Gcc-cvs
https://gcc.gnu.org/g:17fd3555e2c6a747adb166cafa01b794d3ef6ed5

commit 17fd3555e2c6a747adb166cafa01b794d3ef6ed5
Author: Alexandre Oliva 
Date:   Sun Dec 1 06:58:50 2024 -0300

ifcombine: simplify and check for build error

Diff:
---
 gcc/gimple-fold.cc| 117 +-
 gcc/testsuite/gcc.dg/field-merge-12.c |  33 ++
 2 files changed, 79 insertions(+), 71 deletions(-)

diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
index 988e552180c9..fa86aa9665f7 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -7446,9 +7446,6 @@ maybe_fold_comparisons_from_match_pd (tree type, enum 
tree_code code,
*PBITSIZE is set to the number of bits in the reference, *PBITPOS is
set to the starting bit number.
 
-   If the innermost field can be completely contained in a mode-sized
-   unit, *PMODE is set to that mode.  Otherwise, it is set to VOIDmode.
-
*PVOLATILEP is set to 1 if the any expression encountered is volatile;
otherwise it is not changed.
 
@@ -7456,10 +7453,8 @@ maybe_fold_comparisons_from_match_pd (tree type, enum 
tree_code code,
 
*PREVERSEP is set to the storage order of the field.
 
-   *PMASK is set to the mask used.  This is either contained in a
-   BIT_AND_EXPR or derived from the width of the field.
-
*PAND_MASK is set to the mask found in a BIT_AND_EXPR, if any.
+   If PAND_MASK *is NULL, BIT_AND_EXPR is not recognized.
 
*XOR_P is to be FALSE if EXP might be a XOR used in a compare, in which
case, if XOR_CMP_OP is a zero constant, it will be overridden with *PEXP,
@@ -7478,10 +7473,9 @@ maybe_fold_comparisons_from_match_pd (tree type, enum 
tree_code code,
 
 static tree
 decode_field_reference (tree *pexp, HOST_WIDE_INT *pbitsize,
-   HOST_WIDE_INT *pbitpos, machine_mode *pmode,
+   HOST_WIDE_INT *pbitpos,
bool *punsignedp, bool *preversep, bool *pvolatilep,
-   wide_int *pmask, wide_int *pand_mask,
-   bool *xor_p, tree *xor_cmp_op,
+   wide_int *pand_mask, bool *xor_p, tree *xor_cmp_op,
gimple **load, location_t loc[4])
 {
   /* These are from match.pd.  */
@@ -7498,6 +7492,7 @@ decode_field_reference (tree *pexp, HOST_WIDE_INT 
*pbitsize,
   int shiftrt = 0;
   wide_int mask;
   tree res_ops[2];
+  machine_mode mode;
 
   *load = NULL;
 
@@ -7522,7 +7517,7 @@ decode_field_reference (tree *pexp, HOST_WIDE_INT 
*pbitsize,
 }
 
   /* Recognize and save a masking operation.  */
-  if (gimple_bit_and_cst (exp, res_ops, follow_all_ssa_edges))
+  if (pand_mask && gimple_bit_and_cst (exp, res_ops, follow_all_ssa_edges))
 {
   loc[1] = gimple_location (SSA_NAME_DEF_STMT (exp));
   exp = res_ops[0];
@@ -7600,11 +7595,10 @@ decode_field_reference (tree *pexp, HOST_WIDE_INT 
*pbitsize,
   poly_int64 poly_bitsize, poly_bitpos;
   int unsignedp, reversep = *preversep, volatilep = *pvolatilep;
   inner = get_inner_reference (exp, &poly_bitsize, &poly_bitpos, &offset,
-  pmode, &unsignedp, &reversep, &volatilep);
+  &mode, &unsignedp, &reversep, &volatilep);
 
   HOST_WIDE_INT bs, bp;
-  if ((inner == exp && !and_mask.get_precision ())
-  || !poly_bitsize.is_constant (&bs)
+  if (!poly_bitsize.is_constant (&bs)
   || !poly_bitpos.is_constant (&bp)
   || bs <= shiftrt
   || offset != 0
@@ -7649,13 +7643,13 @@ decode_field_reference (tree *pexp, HOST_WIDE_INT 
*pbitsize,
   /* Compute the mask to access the bitfield.  */
   precision = *pbitsize;
 
-  mask = wi::mask (*pbitsize, false, precision);
-
   /* Merge it with the mask we found in the BIT_AND_EXPR, if any.  */
   if (and_mask.get_precision () != 0)
-mask &= wide_int::from (and_mask, precision, UNSIGNED);
+{
+  and_mask = wide_int::from (and_mask, precision, UNSIGNED);
+  mask &= and_mask;
+}
 
-  *pmask = mask;
   *pand_mask = and_mask;
   return inner;
 }
@@ -7913,10 +7907,8 @@ fold_truth_andor_for_ifcombine (enum tree_code code, 
tree truth_type,
   HOST_WIDE_INT rnbitsize, rnbitpos, rnprec;
   bool ll_unsignedp, lr_unsignedp, rl_unsignedp, rr_unsignedp;
   bool ll_reversep, lr_reversep, rl_reversep, rr_reversep;
-  machine_mode ll_mode, lr_mode, rl_mode, rr_mode;
   scalar_int_mode lnmode, lnmode2, rnmode;
-  wide_int ll_mask, lr_mask, rl_mask, rr_mask;
-  wide_int ll_and_mask, lr_and_mask, rl_and_mask, rr_and_mask;
+  wide_int ll_and_mask, rl_and_mask;
   wide_int l_const, r_const;
   tree lntype, rntype, result;
   HOST_WIDE_INT first_bit, end_bit;
@@ -7987,25 +7979,21 @@ fold_truth_andor_for_ifcombine (enum tree_code code, 
tree truth_type,
   ll_reversep = lr_reversep = rl_reversep = rr_reversep = 0;
   volatilep = 0;
   bool l_xor = false, r_xor = false;
-  ll_inner = decode_field_reference (&ll_arg,
-&ll_bitsize, &ll_bitpos, &ll_mode,
+  ll_inner = decode_field_ref

[gcc r14-11015] [PATCH] modula2: Tidyup remove unnecessary parameters

2024-12-01 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:7e8a67e0237f8d6da6d3de7752368f3d8923d121

commit r14-11015-g7e8a67e0237f8d6da6d3de7752368f3d8923d121
Author: Gaius Mulley 
Date:   Sun Dec 1 23:09:44 2024 +

[PATCH] modula2: Tidyup remove unnecessary parameters

This patch removes ununsed parameters from gm2-compiler/M2Comp.mod.

gcc/m2/ChangeLog:

* gm2-compiler/M2Comp.mod (GenerateDependencies): Remove
unused parameter.
(WriteDep): Remove parameter dep.
(WritePhoneDep): Ditto.

(cherry picked from commit 20486ec75734f3e641a3ade4297f6ba64881bca8)

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-compiler/M2Comp.mod | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/gcc/m2/gm2-compiler/M2Comp.mod b/gcc/m2/gm2-compiler/M2Comp.mod
index 719ae6641dc6..1655f0c941f2 100644
--- a/gcc/m2/gm2-compiler/M2Comp.mod
+++ b/gcc/m2/gm2-compiler/M2Comp.mod
@@ -226,7 +226,7 @@ END GenerateDependenciesFromList ;
   the source code is found in sourcefile.
 *)
 
-PROCEDURE GenerateDependencies (sourcefile: String) ;
+PROCEDURE GenerateDependencies ;
 BEGIN
IF IsDefImp (GetMainModule ())
THEN
@@ -252,7 +252,7 @@ BEGIN
FlushWarnings ; FlushErrors ;
IF GetM () OR GetMM ()
THEN
-  GenerateDependencies (s)
+  GenerateDependencies
END ;
IF NOT PPonly
THEN
@@ -652,7 +652,7 @@ END ReadDepContents ;
WriteDep - write the dependencies and target to file out.
 *)
 
-PROCEDURE WriteDep (dep: String; contents: Index; out: File) ;
+PROCEDURE WriteDep (contents: Index; out: File) ;
 VAR
i, h: CARDINAL ;
line: String ;
@@ -692,7 +692,7 @@ END WriteDep ;
WritePhonyDep - write the dependencies and target to file out.
 *)
 
-PROCEDURE WritePhonyDep (dep: String; contents: Index; out: File) ;
+PROCEDURE WritePhonyDep (contents: Index; out: File) ;
 VAR
i, h: CARDINAL ;
line: String ;
@@ -735,10 +735,10 @@ BEGIN
   END ;
   IF IsNoError (out)
   THEN
- WriteDep (dep, contents, out) ;
+ WriteDep (contents, out) ;
  IF GetMP ()
  THEN
-WritePhonyDep (dep, contents, out)
+WritePhonyDep (contents, out)
  END
   END ;
   IF GetMF () = NIL


[gcc r14-11014] [PATCH] modula2: Remove unused parameter warnings seen in build

2024-12-01 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:92ed383eb0bfa0df8d066a0c282ff266816d495f

commit r14-11014-g92ed383eb0bfa0df8d066a0c282ff266816d495f
Author: Gaius Mulley 
Date:   Sun Dec 1 14:41:40 2024 +

[PATCH] modula2: Remove unused parameter warnings seen in build

This patch removes unused parameters in gm2-compiler/M2Check.mod.
It also removes a --fixme-- and completes the missing code
which type checks unbounded arrays.  The patch also fixes a
build error seen when building m2/stage2/cc1gm2.

gcc/m2/ChangeLog:

* gm2-compiler/M2Check.mod (checkUnboundedArray): New
procedure function.
(checkUnboundedUnbounded): Ditto.
(checkUnbounded): Rewrite to check the unbounded data
type.
(checkPair): Add comment.
(doCheckPair): Add comment.
Remove tinfo parameter from the call to checkTypeKindViolation.
(checkTypeKindViolation): Remove ununsed parameter tinfo.
* gm2-libs-ch/UnixArgs.cc (GM2RTS.h): Remove include.
* gm2-libs-ch/m2rts.h (M2RTS_INIT): New define.
(M2RTS_DEP): Ditto.
(M2RTS_RegisterModule): New prototype.
(GM2RTS.h): Add include to the MC_M2 block.

gcc/testsuite/ChangeLog:

* gm2/iso/fail/testarrayunbounded2.mod: New test.
* gm2/iso/fail/testarrayunbounded3.mod: New test.
* gm2/iso/fail/testarrayunbounded4.mod: New test.
* gm2/iso/fail/testarrayunbounded5.mod: New test.
* gm2/iso/fail/testarrayunbounded6.mod: New test.
* gm2/iso/pass/testarrayunbounded.mod: New test.

(cherry picked from commit 2828ec526eaf5612178b62d48bfd8443c7ecd674)

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-compiler/M2Check.mod| 138 +++--
 gcc/m2/gm2-libs-ch/UnixArgs.cc |   1 -
 gcc/m2/gm2-libs-ch/m2rts.h |   7 +-
 gcc/testsuite/gm2/iso/fail/testarrayunbounded2.mod |  14 +++
 gcc/testsuite/gm2/iso/fail/testarrayunbounded3.mod |  14 +++
 gcc/testsuite/gm2/iso/fail/testarrayunbounded4.mod |  14 +++
 gcc/testsuite/gm2/iso/fail/testarrayunbounded5.mod |  13 ++
 gcc/testsuite/gm2/iso/fail/testarrayunbounded6.mod |  13 ++
 gcc/testsuite/gm2/iso/pass/testarrayunbounded.mod  |  14 +++
 9 files changed, 213 insertions(+), 15 deletions(-)

diff --git a/gcc/m2/gm2-compiler/M2Check.mod b/gcc/m2/gm2-compiler/M2Check.mod
index 1750fe07ecf1..d096646c3877 100644
--- a/gcc/m2/gm2-compiler/M2Check.mod
+++ b/gcc/m2/gm2-compiler/M2Check.mod
@@ -48,7 +48,7 @@ FROM SymbolTable IMPORT NulSym, IsRecord, IsSet, GetDType, 
GetSType, IsType,
 GetMode, GetType, IsUnbounded, IsComposite, 
IsConstructor,
 IsParameter, IsConstString, IsConstLitInternal, 
IsConstLit,
 GetStringLength, GetProcedureProcType, IsHiddenType,
-IsHiddenReallyPointer ;
+IsHiddenReallyPointer, GetDimension ;
 
 FROM M2GCCDeclare IMPORT GetTypeMin, GetTypeMax ;
 FROM M2System IMPORT Address ;
@@ -259,12 +259,93 @@ BEGIN
 END checkSubrange ;
 
 
+(*
+   checkUnboundedArray - returns status if unbounded is parameter compatible 
with array.
+ It checks all type equivalences of the static array 
for a
+ match with the dynamic (unbounded) array.
+*)
+
+PROCEDURE checkUnboundedArray (result: status;
+   unbounded, array: CARDINAL) : status ;
+VAR
+   dim   : CARDINAL ;
+   ubtype,
+   type  : CARDINAL ;
+BEGIN
+   (* Firstly check to see if we have resolved this as false.  *)
+   IF isFalse (result)
+   THEN
+  RETURN result
+   ELSE
+  Assert (IsUnbounded (unbounded)) ;
+  Assert (IsArray (array)) ;
+  dim := GetDimension (unbounded) ;
+  ubtype := GetType (unbounded) ;
+  type := array ;
+  REPEAT
+ type := GetType (type) ;
+ DEC (dim) ;
+ (* Check type equivalences.  *)
+ IF checkTypeEquivalence (result, type, ubtype) = true
+ THEN
+RETURN true
+ END ;
+ type := SkipType (type) ;
+ (* If we have run out of dimensions we conclude false.  *)
+ IF dim = 0
+ THEN
+RETURN false
+ END ;
+  UNTIL NOT IsArray (type)
+   END ;
+   RETURN false
+END checkUnboundedArray ;
+
+
+(*
+   checkUnboundedUnbounded - check to see if formal and actual are compatible.
+ Both are unbounded parameters.
+*)
+
+PROCEDURE checkUnboundedUnbounded (result: status;
+   tinfo: tInfo;
+   formal, actual: CARDINAL) : status ;
+BEGIN
+   (* Firstly check to see if we have resolved this as false.  *)
+   IF isFalse (result)
+   THEN
+  RETURN result
+   ELSE
+  Assert (IsUnbounded (formal)) ;
+  Assert (IsUnbounded (act

[gcc r15-5845] testsuite: Silence gcc.dg/pr117806.c for default_packed

2024-12-01 Thread Dimitar Dimitrov via Gcc-cvs
https://gcc.gnu.org/g:7151aa12d659fc095687a22688dd0307ebb4845d

commit r15-5845-g7151aa12d659fc095687a22688dd0307ebb4845d
Author: Dimitar Dimitrov 
Date:   Sun Dec 1 16:24:03 2024 +0200

testsuite: Silence gcc.dg/pr117806.c for default_packed

On default_packed targets like PRU, spurious warnings are emitted:
  ...workspace/gcc/gcc/testsuite/gcc.dg/pr117806.c:5:3: warning: 'packed' 
attribute ignored for field of type 'double' [-Wattributes]

Fix by annotating the excess warnings for default_packed targets.

gcc/testsuite/ChangeLog:

* gcc.dg/pr117806.c: Test can spill excess
errors for default_packed targets.

Signed-off-by: Dimitar Dimitrov 

Diff:
---
 gcc/testsuite/gcc.dg/pr117806.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/testsuite/gcc.dg/pr117806.c b/gcc/testsuite/gcc.dg/pr117806.c
index bc2c8c665e73..a01278cdc152 100644
--- a/gcc/testsuite/gcc.dg/pr117806.c
+++ b/gcc/testsuite/gcc.dg/pr117806.c
@@ -1,4 +1,5 @@
 /* { dg-do compile } */
+/* { dg-excess-errors "warnings about ignored 'packed' attribute" { target 
default_packed } } */
 /* { dg-options "-std=c23" } */
 
 struct Test {


[gcc r15-5854] [contrib] validate_failures.py: fix python 3.12 escape sequence warnings

2024-12-01 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:90becd94cf92858555e0e538ec2091f952971453

commit r15-5854-g90becd94cf92858555e0e538ec2091f952971453
Author: Gabi Falk 
Date:   Sun Dec 1 12:18:18 2024 -0700

[contrib] validate_failures.py: fix python 3.12 escape sequence warnings

The warnings:
contrib/testsuite-management/validate_failures.py:65: SyntaxWarning: 
invalid escape sequence '\s'
  _VALID_TEST_RESULTS_REX = re.compile('(%s):\s*(\S+)\s*(.*)'
contrib/testsuite-management/validate_failures.py:77: SyntaxWarning: 
invalid escape sequence '\.'
  _EXP_LINE_REX = re.compile('^Running (?:.*:)?(.*) \.\.\.\n')

contrib/ChangeLog:
* testsuite-management/validate_failures.py: Change re.compile()
function arguments to Python raw strings.

Diff:
---
 contrib/testsuite-management/validate_failures.py | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/contrib/testsuite-management/validate_failures.py 
b/contrib/testsuite-management/validate_failures.py
index f81ac4f135d2..e5188bbf105c 100755
--- a/contrib/testsuite-management/validate_failures.py
+++ b/contrib/testsuite-management/validate_failures.py
@@ -62,7 +62,7 @@ import sys
 
 _VALID_TEST_RESULTS = [ 'FAIL', 'UNRESOLVED', 'XPASS', 'ERROR' ]
 # :  

[gcc r15-5856] RISC-V: Fix RVV strided load/store testcases failure

2024-12-01 Thread Pan Li via Gcc-cvs
https://gcc.gnu.org/g:aedb306a457496bac3b0029c6b4a1e63c738ddde

commit r15-5856-gaedb306a457496bac3b0029c6b4a1e63c738ddde
Author: Pan Li 
Date:   Fri Nov 29 12:01:33 2024 +0800

RISC-V: Fix RVV strided load/store testcases failure

This patch would like to fix the testcases failures of strided
load/store after sorts of optimization option passing to testcase.

* Add no strict align for vector option.
* Adjust dg-final by any-opts and/or no-opts if the rtl dump changes
  on different optimization options (like O2, O3, zvl).

The below test suites are passed for this patch.
* The rv64gcv fully regression test.

It is test only patch and obvious up to a point, will commit it
directly if no comments in next 48H.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/autovec/strided/strided_ld_st-1-f16.c: Fix
the failed test by target any-opts and/or no-opts.
* gcc.target/riscv/rvv/autovec/strided/strided_ld_st-1-f32.c: Ditto
* gcc.target/riscv/rvv/autovec/strided/strided_ld_st-1-f64.c: Ditto
* gcc.target/riscv/rvv/autovec/strided/strided_ld_st-1-i16.c: Ditto
* gcc.target/riscv/rvv/autovec/strided/strided_ld_st-1-i32.c: Ditto
* gcc.target/riscv/rvv/autovec/strided/strided_ld_st-1-i64.c: Ditto
* gcc.target/riscv/rvv/autovec/strided/strided_ld_st-1-i8.c: Ditto
* gcc.target/riscv/rvv/autovec/strided/strided_ld_st-1-u16.c: Ditto
* gcc.target/riscv/rvv/autovec/strided/strided_ld_st-1-u32.c: Ditto
* gcc.target/riscv/rvv/autovec/strided/strided_ld_st-1-u64.c: Ditto
* gcc.target/riscv/rvv/autovec/strided/strided_ld_st-1-u8.c: Ditto

Signed-off-by: Pan Li 

Diff:
---
 .../rvv/autovec/strided/strided_ld_st-1-f16.c  | 32 +++
 .../rvv/autovec/strided/strided_ld_st-1-f32.c  | 32 +++
 .../rvv/autovec/strided/strided_ld_st-1-f64.c  |  2 +-
 .../rvv/autovec/strided/strided_ld_st-1-i16.c  | 32 +++
 .../rvv/autovec/strided/strided_ld_st-1-i32.c  | 46 ++
 .../rvv/autovec/strided/strided_ld_st-1-i64.c  |  2 +-
 .../riscv/rvv/autovec/strided/strided_ld_st-1-i8.c | 32 +++
 .../rvv/autovec/strided/strided_ld_st-1-u16.c  | 32 +++
 .../rvv/autovec/strided/strided_ld_st-1-u32.c  | 46 ++
 .../rvv/autovec/strided/strided_ld_st-1-u64.c  |  2 +-
 .../riscv/rvv/autovec/strided/strided_ld_st-1-u8.c | 32 +++
 11 files changed, 231 insertions(+), 59 deletions(-)

diff --git 
a/gcc/testsuite/gcc.target/riscv/rvv/autovec/strided/strided_ld_st-1-f16.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/strided/strided_ld_st-1-f16.c
index a128e9fb20aa..4098774ba381 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/strided/strided_ld_st-1-f16.c
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/strided/strided_ld_st-1-f16.c
@@ -1,13 +1,31 @@
 /* { dg-do compile } */
-/* { dg-options "-march=rv64gcv_zvfh -mabi=lp64d -fno-vect-cost-model 
-fdump-rtl-expand-details" } */
+/* { dg-options "-march=rv64gcv_zvfh -mabi=lp64d -mno-vector-strict-align 
-fno-vect-cost-model -fdump-rtl-expand-details" } */
 
 #include "strided_ld_st.h"
 
 DEF_STRIDED_LD_ST_FORM_1(_Float16)
 
-/* { dg-final { scan-rtl-dump-times ".MASK_LEN_STRIDED_LOAD " 4 "expand" { 
target { any-opts "-O3" } } } } */
-/* { dg-final { scan-rtl-dump-times ".MASK_LEN_STRIDED_STORE " 4 "expand" { 
target { any-opts "-O3" } } } } */
-/* { dg-final { scan-rtl-dump-times ".MASK_LEN_STRIDED_LOAD " 2 "expand" { 
target { any-opts "-O2" } } } } */
-/* { dg-final { scan-rtl-dump-times ".MASK_LEN_STRIDED_STORE " 2 "expand" { 
target { any-opts "-O2" } } } } */
-/* { dg-final { scan-assembler-times {vlse16.v} 1 } } */
-/* { dg-final { scan-assembler-times {vsse16.v} 1 } } */
+/* { dg-final { scan-rtl-dump-times ".MASK_LEN_STRIDED_LOAD " 4 "expand" { 
target {
+ any-opts "-O3"
+ no-opts "-mrvv-vector-bits=zvl"
+   } } } } */
+/* { dg-final { scan-rtl-dump-times ".MASK_LEN_STRIDED_STORE " 4 "expand" { 
target {
+ any-opts "-O3"
+ no-opts "-mrvv-vector-bits=zvl"
+   } } } } */
+
+/* { dg-final { scan-rtl-dump-times ".MASK_LEN_STRIDED_LOAD " 2 "expand" { 
target {
+ any-opts "-O2"
+ no-opts "-mrvv-vector-bits=zvl"
+   } } } } */
+/* { dg-final { scan-rtl-dump-times ".MASK_LEN_STRIDED_STORE " 2 "expand" { 
target {
+ any-opts "-O2"
+ no-opts "-mrvv-vector-bits=zvl"
+   } } } } */
+
+/* { dg-final { scan-assembler-times {vlse16.v} 1 { target {
+ no-opts "-mrvv-vector-bits=zvl"
+   } } } } */
+/* { dg-final { scan-assembler-times {vsse16.v} 1 { target {
+ no-opts "-mrvv-vector-bits=zvl"
+   } } } } */
diff --git 
a/gcc/testsuite/gcc.target/riscv/rvv/autovec/strided/strided_ld_st-1-f32.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/strided/strided_ld_st-1-f32.c
index 621c26a2df2c..e1d1063ec8c2 100644
--- a/gcc/testsuite

[gcc r15-5857] RISC-V: Fix incorrect optimization options passing to widden

2024-12-01 Thread Pan Li via Gcc-cvs
https://gcc.gnu.org/g:12e30d82cc7ef614ec7a7f2bfae219fe8f99d94b

commit r15-5857-g12e30d82cc7ef614ec7a7f2bfae219fe8f99d94b
Author: Pan Li 
Date:   Fri Nov 29 11:57:34 2024 +0800

RISC-V: Fix incorrect optimization options passing to widden

Like the strided load/store, the testcases of vector widen are
designed to pick up different sorts of optimization options but actually
these option are ignored according to the Execution log of gcc.log.
This patch would like to make it correct almost the same as what we fixed 
for
strided load/store.

The below test suites are passed for this patch.
* The rv64gcv fully regression test.

It is test only patch and obvious up to a point, will commit it
directly if no comments in next 48H.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/rvv.exp: Fix the incorrect optimization
options passing to testcases.

Signed-off-by: Pan Li 

Diff:
---
 gcc/testsuite/gcc.target/riscv/rvv/rvv.exp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.target/riscv/rvv/rvv.exp 
b/gcc/testsuite/gcc.target/riscv/rvv/rvv.exp
index 8f5860c46b42..87c5ecb1a8b1 100644
--- a/gcc/testsuite/gcc.target/riscv/rvv/rvv.exp
+++ b/gcc/testsuite/gcc.target/riscv/rvv/rvv.exp
@@ -90,7 +90,7 @@ set AUTOVEC_TEST_OPTS [list \
   {-ftree-vectorize -O2 -mrvv-max-lmul=m4} ]
 foreach op $AUTOVEC_TEST_OPTS {
   dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/autovec/widen/*.\[cS\]]] 
\
-"" "$op"
+"$op" ""
 }
 
 # VLS-VLMAX tests


[gcc r15-5858] x86: Correct comments for pass_apx_nf_convert

2024-12-01 Thread H.J. Lu via Gcc-cvs
https://gcc.gnu.org/g:e4dd0075aa998d522edd0da552d60a942eaae78a

commit r15-5858-ge4dd0075aa998d522edd0da552d60a942eaae78a
Author: H.J. Lu 
Date:   Mon Dec 2 13:10:46 2024 +0800

x86: Correct comments for pass_apx_nf_convert

Change pass_rpad to pass_apx_nf_convert in pass_apx_nf_convert comments.

* config/i386/i386-features.cc (pass_apx_nf_convert): Change
pass_rpad to pass_apx_nf_convert in comments.

Signed-off-by: H.J. Lu 

Diff:
---
 gcc/config/i386/i386-features.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/config/i386/i386-features.cc b/gcc/config/i386/i386-features.cc
index 003b003e09c1..814c233e95d3 100644
--- a/gcc/config/i386/i386-features.cc
+++ b/gcc/config/i386/i386-features.cc
@@ -3440,7 +3440,7 @@ public:
 {
   return ix86_apx_nf_convert ();
 }
-}; // class pass_rpad
+}; // class pass_apx_nf_convert
 
 } // anon namespace


[gcc r15-5846] Write binary annotations for CodeView S_INLINESITE symbols

2024-12-01 Thread Mark Harmstone via Gcc-cvs
https://gcc.gnu.org/g:75fe4e2932136c3814e7ba9a2620d395d8f18133

commit r15-5846-g75fe4e2932136c3814e7ba9a2620d395d8f18133
Author: Mark Harmstone 
Date:   Thu Nov 7 03:59:18 2024 +

Write binary annotations for CodeView S_INLINESITE symbols

Add "binary annotations" at the end of CodeView S_INLINESITE symbols,
which are a series of compressed integers that represent how line
numbers map to addresses.

This requires assembler support; you will need commit b3aa594d ("gas:
add .cv_ucomp and .cv_scomp pseudo-directives") in binutils.

gcc/
* configure.ac (HAVE_GAS_CV_UCOMP): New check.
* configure: Regenerate.
* config.in: Regenerate.
* dwarf2codeview.cc (enum binary_annotation_opcode): Define.
(struct codeview_function): Add htab_next and inline_loc;
(struct cv_func_hasher): Define.
(cv_func_htab): New global variable.
(new_codeview_function): Add new codeview_function to hash table.
(codeview_begin_block): Record location of inline block.
(codeview_end_block): Add dummy source line at end of inline block.
(find_line_function): New function.
(write_binary_annotations): New function.
(write_s_inlinesite): Call write_binary_annotations.
(codeview_debug_finish): Delete cv_func_htab.

Diff:
---
 gcc/config.in |   6 ++
 gcc/configure |  32 
 gcc/configure.ac  |   3 +
 gcc/dwarf2codeview.cc | 203 +-
 4 files changed, 240 insertions(+), 4 deletions(-)

diff --git a/gcc/config.in b/gcc/config.in
index 972c0c2034dc..d8145a1453b4 100644
--- a/gcc/config.in
+++ b/gcc/config.in
@@ -1459,6 +1459,12 @@
 /* Define 0/1 if your assembler supports .cfi_sections. */
 #undef HAVE_GAS_CFI_SECTIONS_DIRECTIVE
 
+/* Define if your assembler supports .cv_ucomp. */
+#ifndef USED_FOR_TARGET
+#undef HAVE_GAS_CV_UCOMP
+#endif
+
+
 /* Define if your assembler supports the .loc discriminator sub-directive. */
 #ifndef USED_FOR_TARGET
 #undef HAVE_GAS_DISCRIMINATOR
diff --git a/gcc/configure b/gcc/configure
index 8bb71cfe3485..bab4181a940f 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -25943,6 +25943,38 @@ $as_echo "#define HAVE_GAS_BASE64 1" >>confdefs.h
 fi
 
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for .cv_ucomp" >&5
+$as_echo_n "checking assembler for .cv_ucomp... " >&6; }
+if ${gcc_cv_as_cv_ucomp+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  gcc_cv_as_cv_ucomp=no
+  if test x$gcc_cv_as != x; then
+$as_echo '.cv_ucomp 0' > conftest.s
+if { ac_try='$gcc_cv_as $gcc_cv_as_flags  -o conftest.o conftest.s >&5'
+  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }
+then
+   gcc_cv_as_cv_ucomp=yes
+else
+  echo "configure: failed program was" >&5
+  cat conftest.s >&5
+fi
+rm -f conftest.o conftest.s
+  fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_as_cv_ucomp" >&5
+$as_echo "$gcc_cv_as_cv_ucomp" >&6; }
+if test $gcc_cv_as_cv_ucomp = yes; then
+
+$as_echo "#define HAVE_GAS_CV_UCOMP 1" >>confdefs.h
+
+fi
+
+
 # gnu_indirect_function type is an extension proposed at
 # http://groups.google/com/group/generic-abi/files. It allows dynamic runtime
 # selection of function implementation
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 88a1a44fcf75..b1b21cf4d7b2 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -3065,6 +3065,9 @@ gcc_GAS_CHECK_FEATURE([.base64], gcc_cv_as_base64,,
.base64 
"Tm9uIHB1ZG9yIGVzdCBuaWwgc2NpcmUsIHB1ZG9yIG5pbCBkaXNjZXJlIHZlbGxlLgo="],,
 [AC_DEFINE(HAVE_GAS_BASE64, 1, [Define if your assembler supports .base64.])])
 
+gcc_GAS_CHECK_FEATURE([.cv_ucomp], gcc_cv_as_cv_ucomp,,[.cv_ucomp 0],,
+[AC_DEFINE(HAVE_GAS_CV_UCOMP, 1, [Define if your assembler supports 
.cv_ucomp.])])
+
 # gnu_indirect_function type is an extension proposed at
 # http://groups.google/com/group/generic-abi/files. It allows dynamic runtime
 # selection of function implementation
diff --git a/gcc/dwarf2codeview.cc b/gcc/dwarf2codeview.cc
index a0809d893430..19ec58d096ee 100644
--- a/gcc/dwarf2codeview.cc
+++ b/gcc/dwarf2codeview.cc
@@ -1086,6 +1086,25 @@ enum cv_amd64_register {
   CV_AMD64_YMM15D3 = 687
 };
 
+/* This is enum BinaryAnnotationOpcode in Microsoft's cvinfo.h.  */
+
+enum binary_annotation_opcode {
+  ba_op_invalid,
+  ba_op_code_offset,
+  ba_op_change_code_offset_base,
+  ba_op_change_code_offset,
+  ba_op_change_code_length,
+  ba_op_change_file,
+  ba_op_change_line_offset,
+  ba_op_change_line_end_delta,
+  ba_op_change_range_kind,
+  ba_op_change_column_start,
+  ba_op_change_column_end_delta,
+  ba_op_change_code_offset_and_line_offset,
+  ba_op_change_code_length_and_code_offset,
+  ba_op_change_col

[gcc r15-5850] [PATCH v7 11/12] Replace the original CRC loops with a faster CRC calculation

2024-12-01 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:4d2b9202fe94c54e63fb07d48293a78da3d82532

commit r15-5850-g4d2b9202fe94c54e63fb07d48293a78da3d82532
Author: Mariam Arutunian 
Date:   Mon Nov 11 13:01:19 2024 -0700

[PATCH v7 11/12] Replace the original CRC loops with a faster CRC 
calculation

After the loop exit an internal function call (CRC, CRC_REV) is added, and 
its
result is assigned to the output CRC variable (the variable where the
calculated CRC is stored after the loop execution).  The removal of the 
loop is
left to CFG cleanup and DCE.

gcc/

* gimple-crc-optimization.cc (optimize_crc_loop): New function.
(execute): Add optimize_crc_loop function call.

Diff:
---
 gcc/gimple-crc-optimization.cc | 78 ++
 1 file changed, 78 insertions(+)

diff --git a/gcc/gimple-crc-optimization.cc b/gcc/gimple-crc-optimization.cc
index fced04fc398a..59fe5f656149 100644
--- a/gcc/gimple-crc-optimization.cc
+++ b/gcc/gimple-crc-optimization.cc
@@ -225,6 +225,11 @@ class crc_optimization {
   /* Returns phi statement which may hold the calculated CRC.  */
   gphi *get_output_phi ();
 
+  /* Attempts to optimize a CRC calculation loop by replacing it with a call to
+ an internal function (IFN_CRC or IFN_CRC_REV).
+ Returns true if replacement is succeeded, otherwise false.  */
+  bool optimize_crc_loop (gphi *output_crc);
+
  public:
   crc_optimization () : m_visited_stmts (BITMAP_ALLOC (NULL)),
m_crc_loop (nullptr), m_polynomial (0)
@@ -1207,6 +1212,73 @@ crc_optimization::get_output_phi ()
   return nullptr;
 }
 
+/* Attempts to optimize a CRC calculation loop by replacing it with a call to
+   an internal function (IFN_CRC or IFN_CRC_REV).
+   Returns true if replacement is succeeded, otherwise false.  */
+
+bool
+crc_optimization::optimize_crc_loop (gphi *output_crc)
+{
+  if (!output_crc)
+{
+  if (dump_file)
+   fprintf (dump_file, "Couldn't determine output CRC.\n");
+  return false;
+}
+
+  if (!m_data_arg)
+{
+  if (dump_file && (dump_flags & TDF_DETAILS))
+   fprintf (dump_file,
+"Data and CRC are xor-ed before for loop.  Initializing data "
+"with 0.\n");
+  /* Create a new variable for the data.
+   Determine the data's size with the loop iteration count.  */
+  unsigned HOST_WIDE_INT
+   data_size = tree_to_uhwi (m_crc_loop->nb_iterations) + 1;
+  tree type = build_nonstandard_integer_type (data_size, 1);
+ /* For the CRC calculation, it doesn't matter CRC is calculated for the
+   (CRC^data, 0) or (CRC, data).  */
+  m_data_arg = build_int_cstu (type, 0);
+}
+
+  /* Build tree node for the polynomial from its constant value.  */
+  tree polynomial_arg = build_int_cstu (TREE_TYPE (m_crc_arg), m_polynomial);
+  gcc_assert (polynomial_arg);
+
+  internal_fn ifn;
+  if (m_is_bit_forward)
+ifn = IFN_CRC;
+  else
+ifn = IFN_CRC_REV;
+
+  tree phi_result = gimple_phi_result (output_crc);
+  location_t loc;
+  loc = EXPR_LOCATION (phi_result);
+
+  /* Add IFN call and write the return value in the phi_result.  */
+  gcall *call
+  = gimple_build_call_internal (ifn, 3,
+   m_crc_arg,
+   m_data_arg,
+   polynomial_arg);
+
+  gimple_call_set_lhs (call, phi_result);
+  gimple_set_location (call, loc);
+  gimple_stmt_iterator si = gsi_start_bb (output_crc->bb);
+  gsi_insert_before (&si, call, GSI_SAME_STMT);
+
+  /* Remove phi statement, which was holding CRC result.  */
+  gimple_stmt_iterator tmp_gsi = gsi_for_stmt (output_crc);
+  remove_phi_node (&tmp_gsi, false);
+
+  /* Alter the exit condition of the loop to always exit.  */
+  gcond* loop_exit_cond = get_loop_exit_condition (m_crc_loop);
+  gimple_cond_make_false (loop_exit_cond);
+  update_stmt (loop_exit_cond);
+  return true;
+}
+
 unsigned int
 crc_optimization::execute (function *fun)
 {
@@ -1263,6 +1335,12 @@ crc_optimization::execute (function *fun)
  if (dump_file)
fprintf (dump_file, "The loop with %d header BB index "
"calculates CRC!\n", m_crc_loop->header->index);
+
+ if (!optimize_crc_loop (output_crc))
+   {
+ if (dump_file)
+   fprintf (dump_file, "Couldn't generate faster CRC code.\n");
+   }
}
 }
   return 0;


[gcc r15-5848] [PATCH v6 09/12] Add symbolic execution support.

2024-12-01 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:148e20466c2c246df9472efed0f2ae94cb65a0f8

commit r15-5848-g148e20466c2c246df9472efed0f2ae94cb65a0f8
Author: Matevos Mehrabyan 
Date:   Mon Nov 11 13:00:10 2024 -0700

[PATCH v6 09/12] Add symbolic execution support.

Gives an opportunity to execute the code on bit level, assigning
symbolic values to the variables which don't have initial values.
Supports only CRC specific operations.

Example:

uint8_t crc;
uint8_t pol = 1;
crc = crc ^ pol;

during symbolic execution crc's value will be:
crc(8), crc(7), ... crc(1), crc(0) ^ 1

gcc/
* Makefile.in (OBJS): Add sym-exec/sym-exec-expression.o,
sym-exec/sym-exec-state.o, sym-exec/sym-exec-condition.o.
* configure (sym-exec): New subdir.
* sym-exec/sym-exec-condition.cc: New file.
* sym-exec/sym-exec-condition.h: New file.
* sym-exec/sym-exec-expr-is-a-helper.h: New file.
* sym-exec/sym-exec-expression.cc: New file.
* sym-exec/sym-exec-expression.h: New file.
* sym-exec/sym-exec-state.cc: New file.
* sym-exec/sym-exec-state.h: New file.

Co-authored-by: Mariam Arutunian 

Diff:
---
 gcc/Makefile.in  |3 +
 gcc/configure|2 +-
 gcc/sym-exec/sym-exec-condition.cc   |   86 ++
 gcc/sym-exec/sym-exec-condition.h|   63 +
 gcc/sym-exec/sym-exec-expr-is-a-helper.h |  287 
 gcc/sym-exec/sym-exec-expression.cc  |  490 +++
 gcc/sym-exec/sym-exec-expression.h   |  332 +
 gcc/sym-exec/sym-exec-state.cc   | 2321 ++
 gcc/sym-exec/sym-exec-state.h|  471 ++
 9 files changed, 4054 insertions(+), 1 deletion(-)

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 4cfe383ba8a1..d250b4cb0a63 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1731,6 +1731,9 @@ OBJS = \
tree-logical-location.o \
tree-loop-distribution.o \
gimple-crc-optimization.o \
+   sym-exec/sym-exec-expression.o \
+   sym-exec/sym-exec-state.o \
+   sym-exec/sym-exec-condition.o \
tree-nested.o \
tree-nrv.o \
tree-object-size.o \
diff --git a/gcc/configure b/gcc/configure
index bab4181a940f..d21b33e2b6c0 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -36295,7 +36295,7 @@ $as_echo "$as_me: executing $ac_file commands" >&6;}
 "depdir":C) $SHELL $ac_aux_dir/mkinstalldirs $DEPDIR ;;
 "gccdepdir":C)
   ${CONFIG_SHELL-/bin/sh} $ac_aux_dir/mkinstalldirs build/$DEPDIR
-  for lang in $subdirs c-family common analyzer text-art rtl-ssa
+  for lang in $subdirs c-family common analyzer text-art rtl-ssa sym-exec
   do
   ${CONFIG_SHELL-/bin/sh} $ac_aux_dir/mkinstalldirs $lang/$DEPDIR
   done ;;
diff --git a/gcc/sym-exec/sym-exec-condition.cc 
b/gcc/sym-exec/sym-exec-condition.cc
new file mode 100644
index ..fef03d04d555
--- /dev/null
+++ b/gcc/sym-exec/sym-exec-condition.cc
@@ -0,0 +1,86 @@
+/* Everything defined here is used for representing conditions for bits
+   and their status.
+   Copyright (C) 2022-2024 Free Software Foundation, Inc.
+   Contributed by Matevos Mehrabyan 
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+.  */
+
+#include "sym-exec-condition.h"
+
+/* Constructor where the first argument is the bit left to the condition sign,
+   the second argument is the bit right to the condition sign and the third
+   argument is the code of the condition.  */
+
+bit_condition::bit_condition (value_bit *left, value_bit *right, tree_code 
code)
+{
+  this->m_left = left;
+  this->m_right = right;
+  this->m_code = code;
+  m_type = BIT_CONDITION;
+}
+
+
+/* Copy constructor.  */
+
+bit_condition::bit_condition (const bit_condition &expr)
+{
+  bit_expression::copy (&expr);
+  m_code = expr.get_code ();
+}
+
+
+/* Returns the condition's code.  */
+
+tree_code
+bit_condition::get_code () const
+{
+  return m_code;
+}
+
+
+/* Returns a copy of the condition.  */
+
+value_bit *
+bit_condition::copy () const
+{
+  return new bit_condition (*this);
+}
+
+
+/* Prints the condition's sign.  */
+
+void
+bit_condition::print_expr_sign ()
+{
+  switch (m_code)
+{
+  case GT_EXPR:
+   fprintf (dump_file, " > ");
+   break;
+  case LT_EXPR:
+   fprintf (dump_file, " < ");
+   break;
+

[gcc r15-5849] [PATCH v7 10/12] Verify detected CRC loop with symbolic execution and LFSR matching

2024-12-01 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:dcc6101cb166b4c59afecc2a3cf1d7aa655fe76a

commit r15-5849-gdcc6101cb166b4c59afecc2a3cf1d7aa655fe76a
Author: Mariam Arutunian 
Date:   Mon Nov 11 13:00:37 2024 -0700

[PATCH v7 10/12] Verify detected CRC loop with symbolic execution and LFSR 
matching

Symbolically execute potential CRC loops and check whether the loop actually
calculates CRC (uses LFSR matching).  Calculated CRC and created LFSR are
compared on each iteration of the potential CRC loop.

gcc/

* Makefile.in (OBJS): Add crc-verification.o.
* crc-verification.cc: New file.
* crc-verification.h: New file.
* gimple-crc-optimization.cc (loop_calculates_crc): New function.
(is_output_crc): Likewise.
(swap_crc_and_data_if_needed): Likewise.
(validate_crc_and_data): Likewise.
(optimize_crc_loop): Likewise.
(get_output_phi): Likewise.
(execute): Add check whether potential CRC loop calculates CRC.
* sym-exec/sym-exec-state.cc (create_reversed_lfsr): New function.
(create_forward_lfsr): Likewise.
(last_set_bit): Likewise.
(create_lfsr): Likewise.
* sym-exec/sym-exec-state.h (is_bit_vector): Reorder, make the 
function public and static.
(create_reversed_lfsr) New static function declaration.
(create_forward_lfsr) New static function declaration.

Diff:
---
 gcc/Makefile.in|1 +
 gcc/crc-verification.cc| 1299 
 gcc/crc-verification.h |  162 +
 gcc/gimple-crc-optimization.cc |  316 +-
 gcc/sym-exec/sym-exec-state.cc |  101 
 gcc/sym-exec/sym-exec-state.h  |   11 +
 6 files changed, 1888 insertions(+), 2 deletions(-)

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index d250b4cb0a63..dd6e392a1ef9 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1730,6 +1730,7 @@ OBJS = \
tree-iterator.o \
tree-logical-location.o \
tree-loop-distribution.o \
+   crc-verification.o \
gimple-crc-optimization.o \
sym-exec/sym-exec-expression.o \
sym-exec/sym-exec-state.o \
diff --git a/gcc/crc-verification.cc b/gcc/crc-verification.cc
new file mode 100644
index ..c44a32504b45
--- /dev/null
+++ b/gcc/crc-verification.cc
@@ -0,0 +1,1299 @@
+/* Execute symbolically all paths of the loop.
+   Calculate the value of the polynomial by executing loop with real values to
+   create LFSR state.
+   After each iteration check that final states of calculated CRC values match
+   determined LFSR.
+   Copyright (C) 2022-2024 Free Software Foundation, Inc.
+   Contributed by Mariam Arutunian 
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+.   */
+
+#include "crc-verification.h"
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "backend.h"
+#include "tree.h"
+#include "gimple.h"
+#include "ssa.h"
+#include "gimple-iterator.h"
+#include "tree-cfg.h"
+#include "cfganal.h"
+#include "tree-ssa-loop.h"
+
+/* Check whether defined variable is used outside the loop, only
+   CRC's definition is allowed to be used outside the loop.  */
+
+bool
+crc_symbolic_execution::is_used_outside_the_loop (tree def)
+{
+  imm_use_iterator imm_iter;
+  gimple *use_stmt;
+  FOR_EACH_IMM_USE_STMT (use_stmt, imm_iter, def)
+{
+  if (!flow_bb_inside_loop_p (m_crc_loop, use_stmt->bb))
+   {
+ if (is_a (use_stmt)
+ && as_a (use_stmt) == m_output_crc)
+   return false;
+ if (dump_file)
+   fprintf (dump_file, "Defined variable is used outside the loop.\n");
+ return true;
+   }
+}
+  return false;
+}
+
+/* Calculate value of the rhs operation of GS assigment statement
+   and assign it to lhs variable.  */
+
+bool
+crc_symbolic_execution::execute_assign_statement (const gassign *gs)
+{
+  enum tree_code rhs_code = gimple_assign_rhs_code (gs);
+  tree lhs = gimple_assign_lhs (gs);
+  if (dump_file && (dump_flags & TDF_DETAILS))
+fprintf (dump_file, "lhs type : %s \n",
+get_tree_code_name (TREE_CODE (lhs)));
+
+  /* This will filter some normal cases too.  Ex.  usage of array.  */
+  if (TREE_CODE (lhs) != SSA_NAME)
+return false;
+
+  /* Check uses only when m_output_crc is known.  */
+  if (m_output_crc)
+if (i

[gcc r15-5847] [PATCH v7 08/12] Add a new pass for naive CRC loops detection

2024-12-01 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:062ad209e496a69925b1ac1d80d9b99c54801830

commit r15-5847-g062ad209e496a69925b1ac1d80d9b99c54801830
Author: Mariam Arutunian 
Date:   Mon Nov 11 12:59:04 2024 -0700

[PATCH v7 08/12] Add a new pass for naive CRC loops detection

This patch adds a new compiler pass aimed at identifying naive CRC
implementations, characterized by the presence of a loop calculating
a CRC (polynomial long division).  Upon detection of a potential CRC,
the pass prints an informational message.

Performs CRC optimization if optimization level is >= 2 and if
fno_gimple_crc_optimization given.

This pass is added for the detection and optimization of naive CRC
implementations, improving the efficiency of CRC-related computations.

This patch includes only initial fast checks for filtering out non-CRCs,
detected possible CRCs verification and optimization parts will be
provided in subsequent patches.

gcc/

* Makefile.in (OBJS): Add gimple-crc-optimization.o.
* common.opt (foptimize-crc): New option.
* common.opt.urls: Regenerate to add foptimize-crc.
* doc/invoke.texi (-foptimize-crc): Add documentation.
* gimple-crc-optimization.cc: New file.
* opts.cc (default_options_table): Add OPT_foptimize_crc.
(enable_fdo_optimizations): Enable optimize_crc.
* passes.def (pass_crc_optimization): Add new pass.
* timevar.def (TV_GIMPLE_CRC_OPTIMIZATION): New timevar.
* tree-pass.h (make_pass_crc_optimization): New extern function
declaration.

Diff:
---
 gcc/Makefile.in|1 +
 gcc/common.opt |   10 +
 gcc/common.opt.urls|3 +
 gcc/doc/invoke.texi|   16 +-
 gcc/gimple-crc-optimization.cc | 1003 
 gcc/opts.cc|2 +
 gcc/passes.def |1 +
 gcc/timevar.def|1 +
 gcc/tree-pass.h|1 +
 9 files changed, 1037 insertions(+), 1 deletion(-)

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index d2fe82187379..4cfe383ba8a1 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1730,6 +1730,7 @@ OBJS = \
tree-iterator.o \
tree-logical-location.o \
tree-loop-distribution.o \
+   gimple-crc-optimization.o \
tree-nested.o \
tree-nrv.o \
tree-object-size.o \
diff --git a/gcc/common.opt b/gcc/common.opt
index bb226ac61e6a..a42537c5f1ed 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -2422,6 +2422,16 @@ fsave-optimization-record
 Common Var(flag_save_optimization_record) Optimization
 Write a SRCFILE.opt-record.json file detailing what optimizations were 
performed.
 
+foptimize-crc
+Common Var(flag_optimize_crc) Optimization
+Detect loops calculating CRC and replace with faster implementation.
+If the target supports CRC instruction and the CRC loop uses the same
+polynomial as the one used in the CRC instruction, directly replace with the
+corresponding CRC instruction.
+Otherwise, if the target supports carry-less-multiplication instruction,
+generate CRC using it.
+If neither case applies, generate table-based CRC.
+
 foptimize-register-move
 Common Ignore
 Does nothing. Preserved for backward compatibility.
diff --git a/gcc/common.opt.urls b/gcc/common.opt.urls
index e9e818d86deb..01033a90795b 100644
--- a/gcc/common.opt.urls
+++ b/gcc/common.opt.urls
@@ -1022,6 +1022,9 @@ UrlSuffix(gcc/Developer-Options.html#index-fopt-info)
 fsave-optimization-record
 UrlSuffix(gcc/Developer-Options.html#index-fsave-optimization-record)
 
+foptimize-crc
+UrlSuffix(gcc/Optimize-Options.html#index-foptimize-crc)
+
 foptimize-sibling-calls
 UrlSuffix(gcc/Optimize-Options.html#index-foptimize-sibling-calls)
 
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index fa2532f437b6..e27a92c270af 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -605,7 +605,7 @@ Objective-C and Objective-C++ Dialects}.
 -fno-peephole2  -fno-printf-return-value  -fno-sched-interblock
 -fno-sched-spec  -fno-signed-zeros
 -fno-toplevel-reorder  -fno-trapping-math  -fno-zero-initialized-in-bss
--fomit-frame-pointer  -foptimize-sibling-calls
+-fomit-frame-pointer  -foptimize-crc  -foptimize-sibling-calls
 -fpartial-inlining  -fpeel-loops  -fpredictive-commoning
 -fprefetch-loop-arrays
 -fprofile-correction
@@ -12687,6 +12687,7 @@ also turns on the following optimization flags:
 -fipa-ra  -fipa-sra  -fipa-vrp
 -fisolate-erroneous-paths-dereference
 -flra-remat
+-foptimize-crc
 -foptimize-sibling-calls
 -foptimize-strlen
 -fpartial-inlining
@@ -12860,6 +12861,19 @@ leaf functions.
 
 Enabled by default at @option{-O1} and higher.
 
+@opindex foptimize-crc
+@item -foptimize-crc
+Detect loops calculating CRC (performing polynomial long division) and
+replace them with a faster implementation.  Detect 8, 16, 32, and 64 bit CRC,
+with a 

[gcc r15-5853] [PATCH] gcc: configure: Fix the optimization flags cleanup

2024-12-01 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:721a38add973a937b4b60f05cfa17958e892ad27

commit r15-5853-g721a38add973a937b4b60f05cfa17958e892ad27
Author: Slava Barinov 
Date:   Sun Dec 1 11:59:13 2024 -0700

[PATCH] gcc: configure: Fix the optimization flags cleanup

Currently sed command in flag cleanup removes all the -O[0-9] flags, 
ignoring
the context. This leads to issues when the optimization flags is passed to
linker:

CFLAGS="-Os -Wl,-O1 -Wl,--hash-style=gnu"
is converted into
CFLAGS="-Os -Wl,-Wl,--hash-style=gnu"

Which leads to configure failure with ld: unrecognized option '-Wl,-Wl'.

gcc/
* configure.ac: Only remove -O[0-9] if not preceded with comma
* configure: Regenerated

Diff:
---
 gcc/configure| 4 ++--
 gcc/configure.ac | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/gcc/configure b/gcc/configure
index d21b33e2b6c0..e7f85b78ad99 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -5477,8 +5477,8 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
 # optimizations to be activated explicitly by the toplevel.
 case "$CC" in
   */prev-gcc/xgcc*) ;;
-  *) CFLAGS=`echo "$CFLAGS " | sed -e "s/-Ofast[   ]//" -e "s/-O[gs][  
]//" -e "s/-O[0-9]*[]//" `
- CXXFLAGS=`echo "$CXXFLAGS " | sed -e "s/-Ofast[   ]//" -e "s/-O[gs][  
]//" -e "s/-O[0-9]*[]//" ` ;;
+  *) CFLAGS=`echo "$CFLAGS " | sed -e "s/-Ofast[   ]//" -e "s/-O[gs][  
]//" -e "s/[^,]-O[0-9]*[]//" `
+ CXXFLAGS=`echo "$CXXFLAGS " | sed -e "s/-Ofast[   ]//" -e "s/-O[gs][  
]//" -e "s/[^,]-O[0-9]*[]//" ` ;;
 esac
 
 
diff --git a/gcc/configure.ac b/gcc/configure.ac
index b1b21cf4d7b2..a6c650c8f3a9 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -467,8 +467,8 @@ AC_LANG(C++)
 # optimizations to be activated explicitly by the toplevel.
 case "$CC" in
   */prev-gcc/xgcc*) ;;
-  *) CFLAGS=`echo "$CFLAGS " | sed -e "s/-Ofast[[  ]]//" -e "s/-O[[gs]][[  
]]//" -e "s/-O[[0-9]]*[[]]//" `
- CXXFLAGS=`echo "$CXXFLAGS " | sed -e "s/-Ofast[[  ]]//" -e "s/-O[[gs]][[  
]]//" -e "s/-O[[0-9]]*[[]]//" ` ;;
+  *) CFLAGS=`echo "$CFLAGS " | sed -e "s/-Ofast[[  ]]//" -e "s/-O[[gs]][[  
]]//" -e "s/[[^,]]-O[[0-9]]*[[  ]]//" `
+ CXXFLAGS=`echo "$CXXFLAGS " | sed -e "s/-Ofast[[  ]]//" -e "s/-O[[gs]][[  
]]//" -e "s/[[^,]]-O[[0-9]]*[[  ]]//" ` ;;
 esac
 AC_SUBST(CFLAGS)
 AC_SUBST(CXXFLAGS)


[gcc r15-5852] Thanks for the feedback on the first version of the patch. Accordingly:

2024-12-01 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:999aad44aa86e64580d36e74bcc90b48f768cf55

commit r15-5852-g999aad44aa86e64580d36e74bcc90b48f768cf55
Author: Jovan Vukic 
Date:   Sun Dec 1 11:57:41 2024 -0700

Thanks for the feedback on the first version of the patch. Accordingly:

I have corrected the code formatting as requested. I added new tests to
the existing file phi-opt-11.c, instead of creating a new one.

I performed testing before and after applying the patch on the x86
architecture, and I confirm that there are no new regressions.

The logic and general code of the patch itself have not been changed.

> So the A EQ/NE B expression, we can reverse A and B in the expression
> and still get the same result. But don't we have to be more careful for
> the TRUE/FALSE arms of the ternary? For BIT_AND we need ? a : b for
> BIT_IOR we need ? b : a.
>
> I don't see that gets verified in the existing code or after your
> change. I suspect I'm just missing something here. Can you clarify how
> we verify that BIT_AND gets ? a : b for the true/false arms and that
> BIT_IOR gets ? b : a for the true/false arms?

I did not communicate this clearly last time, but the existing optimization
simplifies the expression "(cond & (a == b)) ? a : b" to the simpler "b".
Similarly, the expression "(cond & (a == b)) ? b : a" simplifies to "a".

Thus, the existing and my optimization perform the following
simplifications:

(cond & (a == b)) ? a : b -> b
(cond & (a == b)) ? b : a -> a
(cond | (a != b)) ? a : b -> a
(cond | (a != b)) ? b : a -> b

For this reason, for BIT_AND_EXPR when we have A EQ B, it is sufficient to
confirm that one operand matches the true/false arm and the other matches
the false/true arm. In both cases, we simplify the expression to the third
operand of the ternary operation (i.e., OP0 ? OP1 : OP2 simplifies to OP2).
This is achieved in the value_replacement function after successfully
setting the value of *code within the rhs_is_fed_for_value_replacement
function to EQ_EXPR.

For BIT_IOR_EXPR, the same check is performed for A NE B, except now
*code remains NE_EXPR, and then value_replacement returns the second
operand (i.e., OP0 ? OP1 : OP2 simplifies to OP1).

2024-10-30  Jovan Vukic  

gcc/ChangeLog:

* tree-ssa-phiopt.cc (rhs_is_fed_for_value_replacement): Add a new
optimization opportunity for BIT_IOR_EXPR and a != b.
(operand_equal_for_value_replacement): Ditto.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/phi-opt-11.c: Add more tests.

Diff:
---
 gcc/testsuite/gcc.dg/tree-ssa/phi-opt-11.c | 31 ++-
 gcc/tree-ssa-phiopt.cc | 48 +++---
 2 files changed, 60 insertions(+), 19 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-11.c 
b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-11.c
index 14c82cd52165..d1e284c53252 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-11.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-11.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O1 -fdump-tree-optimized --param 
logical-op-non-short-circuit=1" } */
+/* { dg-options "-O1 -fdump-tree-phiopt2 -fdump-tree-optimized --param 
logical-op-non-short-circuit=1" } */
 
 int f(int a, int b, int c)
 {
@@ -22,4 +22,33 @@ int h(int a, int b, int c, int d)
  return a;
 }
 
+int i(int a, int b, int c)
+{
+  if ((a > c) & (a == b))
+return a;
+  return b;
+}
+
+int j(int a, int b, int c)
+{
+  if ((a > c) & (a == b))
+return b;
+  return a;
+}
+
+int k(int a, int b, int c)
+{
+  if ((a > c) | (a != b))
+return b;
+  return a;
+}
+
+int l(int a, int b, int c)
+{
+  if ((a > c) | (a != b))
+return a;
+  return b;
+}
+
+/* { dg-final { scan-tree-dump-times "if" 0 "phiopt2" } } */
 /* { dg-final { scan-tree-dump-times "if" 0 "optimized" } } */
diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc
index 0d9bc3eb4499..15651809d71b 100644
--- a/gcc/tree-ssa-phiopt.cc
+++ b/gcc/tree-ssa-phiopt.cc
@@ -1077,17 +1077,18 @@ jump_function_from_stmt (tree *arg, gimple *stmt)
   return false;
 }
 
-/* RHS is a source argument in a BIT_AND_EXPR which feeds a conditional
-   of the form SSA_NAME NE 0.
+/* RHS is a source argument in a BIT_AND_EXPR or BIT_IOR_EXPR which feeds
+   a conditional of the form SSA_NAME NE 0.
 
-   If RHS is fed by a simple EQ_EXPR comparison of two values, see if
-   the two input values of the EQ_EXPR match arg0 and arg1.
+   If RHS is fed by a simple EQ_EXPR or NE_EXPR comparison of two values,
+   see if the two input values of the comparison match arg0 and arg1.
 
If so update *code and return TRUE.  Otherwise return FALSE.  */
 
 static bool
 rhs_is_fed_for_value_replacement (const_tree arg0, const_tree arg1,
- enum tree_code *code, const_tree rhs)
+