address_cost should be used, but it reduce cost too much.
So current solution is make constant disp as cheap as possible. */
if (GET_CODE (addr) == PLUS
- && x86_64_immediate_operand (XEXP (addr, 1), Pmode))
+ && x86_64_immediate_operand (XEXP (addr, 1), Pmode)
+ /* Only hanlde (reg + disp) since other forms of addr are mostly LEA,
+ there's no additional cost for the plus of disp. */
+ && register_operand (XEXP (addr, 0), Pmode))
{
*total += 1;
*total += rtx_cost (XEXP (addr, 0), Pmode, PLUS, 0, speed);
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -mavx2 -fno-tree-vectorize -fno-pic" } */
+/* { dg-final { scan-assembler-times {(?n)movl[ \t]+.*, p1\.0\+[0-9]*\(,} 3 } } */
+
+int
+foo (long indx, long indx2, long indx3, long indx4, long indx5, long indx6, long n, int* q)
+{
+ static int p1[10000];
+ int* p2 = p1 + 1000;
+ int* p3 = p1 + 4000;
+ int* p4 = p1 + 8000;
+
+ for (long i = 0; i != n; i++)
+ {
+ /* scan for movl %edi, p1.0+3996(,%rax,4),
+ p1.0+3996 should be propagted into the loop. */
+ p2[indx++] = q[indx++];
+ p3[indx2++] = q[indx2++];
+ p4[indx3++] = q[indx3++];
+ }
+ return p1[indx6] + p1[indx5];
+}