Bug 60012 - Vectorizer generates unnecessary loop versioning for alias
Summary: Vectorizer generates unnecessary loop versioning for alias
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.9.0
: P3 normal
Target Milestone: ---
Assignee: Richard Biener
URL:
Keywords:
Depends on:
Blocks: vectorizer
  Show dependency treegraph
 
Reported: 2014-01-31 17:17 UTC by Bingfeng Mei
Modified: 2014-02-04 09:35 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work: 4.9.0
Known to fail:
Last reconfirmed: 2014-02-03 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bingfeng Mei 2014-01-31 17:17:57 UTC
typedef struct
{
   short real;
   short imag;
} complex16_t;

void
libvector_AccSquareNorm_ref (unsigned long long  *acc,
                             const complex16_t *x, unsigned len)
{
    for (unsigned i = 0; i < len; i++)
    {
        acc[i] +=
            ((unsigned long long)((int)x[i].real * x[i].real)) +
            ((unsigned long long)((int)x[i].imag * x[i].imag));
    }
}

Compiler the code with 
~/scratch/install-x86/bin/gcc tst.c -O2 -S -ftree-vectorize -fdump-tree-vect-details -std=c99

GCC generates unnecessary loop versioning because it cannot disambiguate mem accesses. 

tst.c:12:5: note: versioning for alias required: can't determine dependence between *_8 and _12->real
tst.c:12:5: note: mark for run-time aliasing test between *_8 and _12->real

This should be handled by TBAA info as acc & x clearly point to different data types. But unfortunately, TBAA doesn't handle Anti- & Output- dependencies.
Comment 1 Richard Biener 2014-02-03 14:44:51 UTC
Mine.
Comment 2 Richard Biener 2014-02-04 09:35:19 UTC
Fixed for 4.9.
Comment 3 Richard Biener 2014-02-04 09:35:30 UTC
Author: rguenth
Date: Tue Feb  4 09:34:58 2014
New Revision: 207455

URL: http://gcc.gnu.org/viewcvs?rev=207455&root=gcc&view=rev
Log:
2014-02-04  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/60012
	* tree-vect-data-refs.c (vect_analyze_data_ref_dependence): Apply
	TBAA disambiguation to all DDRs.

	* gcc.dg/vect/pr60012.c: New testcase.

Added:
    trunk/gcc/testsuite/gcc.dg/vect/pr60012.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-vect-data-refs.c