Skip to content

[DA] Does not account for wrapping accesses #149501

@kasuga-fj

Description

@kasuga-fj

Input:

define void @f(ptr %a, i64 %n, i64 %m) {
entry:
  %bound = sub i64 %m, %n
  br label %loop

loop:
  %i = phi i64 [ 0, %entry ], [ %i.next, %loop ]
  %subscript.0 = add i64 %i, %n
  %subscript.1 = add i64 %i, %m
  %idx.0 = getelementptr i8, ptr %a, i64 %subscript.0
  %idx.1 = getelementptr i8, ptr %a, i64 %subscript.1
  store i8 42, ptr %idx.0
  store i8 42, ptr %idx.1
  %i.next = add i64 %i, 1
  %cond.exit = icmp eq i64 %i.next, %bound
  br i1 %cond.exit, label %exit, label %loop

exit:
  ret void
}

Result:

$ opt -passes='print<da>' -disable-output test.ll
Printing analysis 'Dependence Analysis' for function 'f':
Src:  store i8 42, ptr %idx.0, align 1 --> Dst:  store i8 42, ptr %idx.0, align 1
  da analyze - none!
Src:  store i8 42, ptr %idx.0, align 1 --> Dst:  store i8 42, ptr %idx.1, align 1
  da analyze - none!
Src:  store i8 42, ptr %idx.1, align 1 --> Dst:  store i8 42, ptr %idx.1, align 1
  da analyze - none!

godbolt: https://godbolt.org/z/jvascaoo7

At the very least, when both %n and %m are zero, there is a dependency between the two stores within a single iteration.

Here is a portion of the debug output related to the analysis between them:

testing subscript 0, SIV
    src = {(%n + %a),+,1}<%loop>
    dst = {(%m + %a),+,1}<%loop>
	Strong SIV test
	    Coeff = 1, i64
	    SrcConst = (%n + %a), ptr
	    DstConst = (%m + %a), ptr
	    Delta = ((-1 * %m) + %n), i64
	    UpperBound = (-1 + (-1 * %n) + %m), i64
none!

The root cause seems to be that DA uses the backedge-taken count as the iteration count without considering any wrapping accesses (ref: strongSIVtest). In this case, the issue is caused by strongSIVtest, but I suspect similar issues may exist elsewhere in DA.

Metadata

Metadata

Assignees

No one assigned

    Labels

    llvm:analysisIncludes value tracking, cost tables and constant folding

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions