[llvm-bugs] [Bug 27707] New: Wrong unsigned rem operation when compared to zero

via llvm-bugs llvm-bugs at lists.llvm.org
Tue May 10 17:51:48 PDT 2016


https://llvm.org/bugs/show_bug.cgi?id=27707

            Bug ID: 27707
           Summary: Wrong unsigned rem operation when compared to zero
           Product: Polly
           Version: unspecified
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: Optimizer
          Assignee: polly-dev at googlegroups.com
          Reporter: chrisj at codeaurora.org
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

Created attachment 16356
  --> https://llvm.org/bugs/attachment.cgi?id=16356&action=edit
test

Attached test is a simple pointer iteration.

%struct.A = type { i32, i64, i8 }

; Function Attrs: norecurse nounwind
define void @foo1(%struct.A* %a1, %struct.A* readnone %b1) #0 {
entry:
  br label %entry.split

entry.split:                                      ; preds = %entry
  %cmp4 = icmp eq %struct.A* %a1, %b1
  br i1 %cmp4, label %for.cond.cleanup, label %for.body.preheader

for.body.preheader:                               ; preds = %entry.split
  br label %for.body

for.cond.cleanup.loopexit:                        ; preds = %for.body
  br label %for.cond.cleanup

for.cond.cleanup:                                 ; preds =
%for.cond.cleanup.loopexit, %entry.split
  ret void

for.body:                                         ; preds =
%for.body.preheader, %for.body
  %start.05 = phi %struct.A* [ %incdec.ptr, %for.body ], [ %a1,
%for.body.preheader ]
  %a = getelementptr inbounds %struct.A, %struct.A* %start.05, i64 0, i32 0
  %0 = load i32, i32* %a, align 8
  %add = add nsw i32 %0, 1
  store i32 %add, i32* %a, align 8
  %incdec.ptr = getelementptr inbounds %struct.A, %struct.A* %start.05, i64 1
  %cmp = icmp eq %struct.A* %incdec.ptr, %b1
  br i1 %cmp, label %for.cond.cleanup.loopexit, label %for.body
}

Now consider the polly condition generated in the schedule,

opt  -polly-process-unprofitable -polly-code-generator=isl -polly-scops -
analyze test.ll -S

:: isl ast :: foo1 :: entry.split => for.cond.cleanup

if (1 && 0 == (a1 >= b1 + 1 || a1 >= b1 + 24 * floord(a1 - b1, 24) + 1 || b1 >=
a1 + 9223372036854775848))

    if ((a1 - b1) % 24 == 0)
      for (int c0 = 0; c0 < (-a1 + b1) / 24; c0 += 1)
        Stmt_for_body(c0);

else
    {  /* original code */ }


In polly.cond we generate a urem for the (a1 - b1) % 24,

opt  -polly-process-unprofitable -polly-code-generator=isl -polly-scops 
-polly-codegen  test.ll -S


polly.cond:                                       ; preds = %polly.start
  %23 = ptrtoint %struct.A* %a1 to i64
  %24 = ptrtoint %struct.A* %b1 to i64
  %25 = sub nsw i64 %23, %24
  %pexp.zdiv_r = urem i64 %25, 24   <==========
  %26 = icmp eq i64 %pexp.zdiv_r, 0
  br i1 %26, label %polly.then, label %polly.else

In case of when (a1 - b1) is negative, an unsigned remainder operation can give
unexpected results. For example if (a1 - b1) = -48 (0xFFFFFFFFFFFFFFD0), the
modulo with 24 would be 16.
In such cases we need to generate srem.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160511/70a25d1a/attachment.html>


More information about the llvm-bugs mailing list