File: constant-fold.ll

package info (click to toggle)
llvm-toolchain-9 1%3A9.0.1-16.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 882,388 kB
  • sloc: cpp: 4,167,636; ansic: 714,256; asm: 457,610; python: 155,927; objc: 65,094; sh: 42,856; lisp: 26,908; perl: 7,786; pascal: 7,722; makefile: 6,881; ml: 5,581; awk: 3,648; cs: 2,027; xml: 888; javascript: 381; ruby: 156
file content (47 lines) | stat: -rw-r--r-- 1,376 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
; RUN: opt -indvars -S < %s | FileCheck %s

define void @test0(i32* %x) {
entry:
  br label %for.inc

for.inc:                                          ; preds = %for.inc, %entry
  %i.01 = phi i32 [ 0, %entry ], [ %add, %for.inc ]
  %and = and i32 %i.01, 3
  %cmp1 = icmp eq i32 %and, 0
  %cond = select i1 %cmp1, i32 0, i32 1
  store i32 %cond, i32* %x, align 4
  %add = add i32 %i.01, 4
  %cmp = icmp ult i32 %add, 8
  br i1 %cmp, label %for.inc, label %for.end

for.end:                                          ; preds = %for.inc
  ret void
}

; Should fold the condition of the select into constant
; CHECK-LABEL: void @test0(
; CHECK:         icmp eq i32 0, 0

define void @test1(i32* %a) {
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, 8
  %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
}

; Should fold the rem since %mul is multiple of 8
; CHECK-LABEL: @test1(
; CHECK-NOT:     rem
; CHECK:         sext i32 0 to i64