1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 03:33:20 +01:00
llvm-mirror/test/Transforms/IndVarSimplify/replace-srem-by-urem.ll
Hongbin Zheng 29f3927372 [SimplifyIndVar] Constant fold IV users
This patch tries to transform cases like:

for (unsigned i = 0; i < N; i += 2) {
  bool c0 = (i & 0x1) == 0;
  bool c1 = ((i + 1) & 0x1) == 1;
}
To

for (unsigned i = 0; i < N; i += 2) {
  bool c0 = true;
  bool c1 = true;
}

This commit also update test/Transforms/IndVarSimplify/replace-srem-by-urem.ll to prevent constant folding.

Differential Revision: https://reviews.llvm.org/D38272

llvm-svn: 314266
2017-09-27 03:11:46 +00:00

110 lines
3.1 KiB
LLVM

; RUN: opt < %s -indvars -S | FileCheck %s
define void @test0(i32* %a) {
; CHECK-LABEL: @test0(
entry:
br label %for.body
for.body: ; preds = %entry, %for.body
%i.01 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
%rem = srem i32 %i.01, 2
; CHECK-NOT: srem
; CHECK: urem
%idxprom = sext i32 %rem to i64
%arrayidx = getelementptr inbounds i32, i32* %a, i64 %idxprom
store i32 %i.01, i32* %arrayidx, align 4
%inc = add nsw i32 %i.01, 1
%cmp = icmp slt i32 %inc, 64
br i1 %cmp, label %for.body, label %for.end
for.end: ; preds = %for.body
ret void
}
define void @test2(i32* %a, i32 %d) {
; CHECK-LABEL: @test2(
entry:
br label %for.body
for.body: ; preds = %entry, %for.body
%i.01 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
%mul = mul nsw i32 %i.01, 64
%rem = srem i32 %mul, %d
; CHECK-NOT: urem
%idxprom = sext i32 %rem to i64
%arrayidx = getelementptr inbounds i32, i32* %a, i64 %idxprom
store i32 %i.01, i32* %arrayidx, align 4
%inc = add nsw i32 %i.01, 1
%cmp = icmp slt i32 %inc, 64
br i1 %cmp, label %for.body, label %for.end
for.end: ; preds = %for.body
ret void
}
define void @test3(i32* %a) {
; CHECK-LABEL: @test3(
entry:
br label %for.body
for.body: ; preds = %entry, %for.body
%i.01 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
%rem = srem i32 2048, %i.01
; CHECK: urem
; CHECK-NOT: srem
%idxprom = sext i32 %rem to i64
%arrayidx = getelementptr inbounds i32, i32* %a, i64 %idxprom
store i32 %i.01, i32* %arrayidx, align 4
%inc = add nsw i32 %i.01, 1
%cmp = icmp slt i32 %inc, 64
br i1 %cmp, label %for.body, label %for.end
for.end: ; preds = %for.body
ret void
}
define void @test4(i32* %a) {
; CHECK-LABEL: @test4(
entry:
br label %for.body
for.body: ; preds = %entry, %for.body
%i.01 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
%mul = mul nsw i32 %i.01, 64
%rem = srem i32 %mul, 7
; CHECK: urem
; CHECK-NOT: srem
%idxprom = sext i32 %rem to i64
%arrayidx = getelementptr inbounds i32, i32* %a, i64 %idxprom
store i32 %i.01, i32* %arrayidx, align 4
%inc = add nsw i32 %i.01, 1
%cmp = icmp slt i32 %inc, 64
br i1 %cmp, label %for.body, label %for.end
for.end: ; preds = %for.body
ret void
}
define void @test5(i32* %a) {
; CHECK-LABEL: @test5(
entry:
br label %for.body
for.body: ; preds = %entry, %for.body
%i.01 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
%mul = mul nsw i32 %i.01, 64
%rem = srem i32 %mul, 6
; CHECK: urem
; CHECK-NOT: srem
%idxprom = sext i32 %rem to i64
%arrayidx = getelementptr inbounds i32, i32* %a, i64 %idxprom
store i32 %i.01, i32* %arrayidx, align 4
%inc = add nsw i32 %i.01, 1
%cmp = icmp slt i32 %inc, 64
br i1 %cmp, label %for.body, label %for.end
for.end: ; preds = %for.body
ret void
}