[polly] r271707 - Fix modulo compared to zero.
Michael Kruse via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 3 11:51:49 PDT 2016
Author: meinersbur
Date: Fri Jun 3 13:51:48 2016
New Revision: 271707
URL: http://llvm.org/viewvc/llvm-project?rev=271707&view=rev
Log:
Fix modulo compared to zero.
In case of modulo compared to zero, we need to do signed modulo
operation as unsigned can give different results based on whether the
dividend is negative or not.
This addresses llvm.org/PR27707
Contributed-by: Chris Jenneisch <chrisj at codeaurora.org>
Reviewers: _jdoerfert, grosser, Meinersbur
Differential Revision: http://reviews.llvm.org/D20145
Added:
polly/trunk/test/Isl/CodeGen/pointer_rem.ll
Modified:
polly/trunk/lib/CodeGen/IslExprBuilder.cpp
Modified: polly/trunk/lib/CodeGen/IslExprBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/IslExprBuilder.cpp?rev=271707&r1=271706&r2=271707&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/IslExprBuilder.cpp (original)
+++ polly/trunk/lib/CodeGen/IslExprBuilder.cpp Fri Jun 3 13:51:48 2016
@@ -352,7 +352,7 @@ Value *IslExprBuilder::createOpBin(__isl
break;
case isl_ast_op_zdiv_r: // Result only compared against zero
- Res = Builder.CreateURem(LHS, RHS, "pexp.zdiv_r");
+ Res = Builder.CreateSRem(LHS, RHS, "pexp.zdiv_r");
break;
}
Added: polly/trunk/test/Isl/CodeGen/pointer_rem.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/pointer_rem.ll?rev=271707&view=auto
==============================================================================
--- polly/trunk/test/Isl/CodeGen/pointer_rem.ll (added)
+++ polly/trunk/test/Isl/CodeGen/pointer_rem.ll Fri Jun 3 13:51:48 2016
@@ -0,0 +1,48 @@
+; RUN: opt %loadPolly -polly-process-unprofitable -polly-code-generator=isl -polly-scops -polly-ast -analyze -S < %s | FileCheck %s --check-prefix=AST
+; RUN: opt %loadPolly -polly-process-unprofitable -polly-code-generator=isl -polly-scops -polly-codegen -S < %s | FileCheck %s --check-prefix=CODEGEN
+
+target datalayout = "e-m:e-i64:64-i128:128-n8:16:32:64-S128"
+target triple = "aarch64--linux-gnu"
+
+; This test is to ensure that for we generate signed remainder for
+; the polly.cond check.
+
+; AST: isl ast :: foo1
+; AST: if ((a1 - b1) % 24 == 0)
+
+; CODEGEN: define void @foo1
+; CODEGEN: polly.cond:
+; CODEGEN: %pexp.zdiv_r = srem {{.*}}, 24
+
+%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
+}
+
+
More information about the llvm-commits
mailing list