xref: /llvm-project/llvm/test/Transforms/CodeGenPrepare/X86/ext-logicop.ll (revision d9e51e75521d5e33f24a6c1afacae5dbc115f96d)
1cee313d2SEric Christopher; RUN: opt < %s -codegenprepare -S -mtriple=x86_64-unknown-unknown    | FileCheck %s
2cee313d2SEric Christopher
3cee313d2SEric Christopher
4cee313d2SEric Christopher@a = global [10 x i8] zeroinitializer, align 1
5cee313d2SEric Christopherdeclare void @foo()
6cee313d2SEric Christopher
7cee313d2SEric Christopher; ext(and(ld, cst)) -> and(ext(ld), ext(cst))
8*d9e51e75SMatt Arsenaultdefine void @test1(ptr %p, i32 %ll) {
9cee313d2SEric Christopher; CHECK-LABEL: @test1
10cee313d2SEric Christopher; CHECK-NEXT:  entry:
11cee313d2SEric Christopher; CHECK-NEXT:    load
12cee313d2SEric Christopher; CHECK-NEXT:    zext
13cee313d2SEric Christopher; CHECK-NEXT:    and
14cee313d2SEric Christopherentry:
15*d9e51e75SMatt Arsenault  %tmp = load i8, ptr @a, align 1
16cee313d2SEric Christopher  %and = and i8 %tmp, 60
17cee313d2SEric Christopher  %cmp = icmp ugt i8 %and, 20
18cee313d2SEric Christopher  br i1 %cmp, label %if.then, label %if.end
19cee313d2SEric Christopher
20cee313d2SEric Christopherif.then:                                          ; preds = %entry
21cee313d2SEric Christopher  %conv2 = zext i8 %and to i32
22cee313d2SEric Christopher  %add = add nsw i32 %conv2, %ll
23*d9e51e75SMatt Arsenault  store i32 %add, ptr %p, align 4
24cee313d2SEric Christopher  br label %if.end
25cee313d2SEric Christopher
26cee313d2SEric Christopherif.end:                                           ; preds = %if.then, %entry
27cee313d2SEric Christopher  tail call void @foo()
28cee313d2SEric Christopher  ret void
29cee313d2SEric Christopher}
30cee313d2SEric Christopher
31cee313d2SEric Christopher; ext(or(ld, cst)) -> or(ext(ld), ext(cst))
32*d9e51e75SMatt Arsenaultdefine void @test2(ptr %p, i32 %ll) {
33cee313d2SEric Christopher; CHECK-LABEL: @test2
34cee313d2SEric Christopher; CHECK-NEXT:  entry:
35cee313d2SEric Christopher; CHECK-NEXT:    load
36cee313d2SEric Christopher; CHECK-NEXT:    zext
37cee313d2SEric Christopher; CHECK-NEXT:    or
38cee313d2SEric Christopherentry:
39*d9e51e75SMatt Arsenault  %tmp = load i8, ptr @a, align 1
40cee313d2SEric Christopher  %or = or i8 %tmp, 60
41cee313d2SEric Christopher  %cmp = icmp ugt i8 %or, 20
42cee313d2SEric Christopher  br i1 %cmp, label %if.then, label %if.end
43cee313d2SEric Christopher
44cee313d2SEric Christopherif.then:                                          ; preds = %entry
45cee313d2SEric Christopher  %conv2 = zext i8 %or to i32
46cee313d2SEric Christopher  %add = add nsw i32 %conv2, %ll
47*d9e51e75SMatt Arsenault  store i32 %add, ptr %p, align 4
48cee313d2SEric Christopher  br label %if.end
49cee313d2SEric Christopher
50cee313d2SEric Christopherif.end:                                           ; preds = %if.then, %entry
51cee313d2SEric Christopher  tail call void @foo()
52cee313d2SEric Christopher  ret void
53cee313d2SEric Christopher}
54cee313d2SEric Christopher
55cee313d2SEric Christopher; ext(and(shl(ld, cst), cst)) -> and(shl(ext(ld), ext(cst)), ext(cst))
56*d9e51e75SMatt Arsenaultdefine void @test3(ptr %p, i32 %ll) {
57cee313d2SEric Christopher; CHECK-LABEL: @test3
58cee313d2SEric Christopher; CHECK-NEXT:  entry:
59cee313d2SEric Christopher; CHECK-NEXT:    load
60cee313d2SEric Christopher; CHECK-NEXT:    zext
61cee313d2SEric Christopher; CHECK-NEXT:    shl
62cee313d2SEric Christopher; CHECK-NEXT:    and
63cee313d2SEric Christopherentry:
64*d9e51e75SMatt Arsenault  %tmp = load i8, ptr @a, align 1
65cee313d2SEric Christopher  %shl = shl i8 %tmp, 2
66cee313d2SEric Christopher  %and = and i8 %shl, 60
67cee313d2SEric Christopher  %cmp = icmp ugt i8 %and, 20
68cee313d2SEric Christopher  br i1 %cmp, label %if.then, label %if.end
69cee313d2SEric Christopher
70cee313d2SEric Christopherif.then:                                          ; preds = %entry
71cee313d2SEric Christopher  %conv2 = zext i8 %and to i32
72cee313d2SEric Christopher  %add = add nsw i32 %conv2, %ll
73*d9e51e75SMatt Arsenault  store i32 %add, ptr %p, align 4
74cee313d2SEric Christopher  br label %if.end
75cee313d2SEric Christopher
76cee313d2SEric Christopherif.end:                                           ; preds = %if.then, %entry
77cee313d2SEric Christopher  tail call void @foo()
78cee313d2SEric Christopher  ret void
79cee313d2SEric Christopher}
80cee313d2SEric Christopher
81cee313d2SEric Christopher; zext(shrl(ld, cst)) -> shrl(zext(ld), zext(cst))
82*d9e51e75SMatt Arsenaultdefine void @test4(ptr %p, i32 %ll) {
83cee313d2SEric Christopher; CHECK-LABEL: @test4
84cee313d2SEric Christopher; CHECK-NEXT:  entry:
85cee313d2SEric Christopher; CHECK-NEXT:    load
86cee313d2SEric Christopher; CHECK-NEXT:    zext
87cee313d2SEric Christopher; CHECK-NEXT:    lshr
88cee313d2SEric Christopherentry:
89*d9e51e75SMatt Arsenault  %tmp = load i8, ptr @a, align 1
90cee313d2SEric Christopher  %lshr = lshr i8 %tmp, 2
91cee313d2SEric Christopher  %cmp = icmp ugt i8 %lshr, 20
92cee313d2SEric Christopher  br i1 %cmp, label %if.then, label %if.end
93cee313d2SEric Christopher
94cee313d2SEric Christopherif.then:                                          ; preds = %entry
95cee313d2SEric Christopher  %conv2 = zext i8 %lshr to i32
96cee313d2SEric Christopher  %add = add nsw i32 %conv2, %ll
97*d9e51e75SMatt Arsenault  store i32 %add, ptr %p, align 4
98cee313d2SEric Christopher  br label %if.end
99cee313d2SEric Christopher
100cee313d2SEric Christopherif.end:                                           ; preds = %if.then, %entry
101cee313d2SEric Christopher  tail call void @foo()
102cee313d2SEric Christopher  ret void
103cee313d2SEric Christopher}
104cee313d2SEric Christopher
105cee313d2SEric Christopher; ext(xor(ld, cst)) -> xor(ext(ld), ext(cst))
106*d9e51e75SMatt Arsenaultdefine void @test5(ptr %p, i32 %ll) {
107cee313d2SEric Christopher; CHECK-LABEL: @test5
108cee313d2SEric Christopher; CHECK-NEXT:  entry:
109cee313d2SEric Christopher; CHECK-NEXT:    load
110cee313d2SEric Christopher; CHECK-NEXT:    zext
111cee313d2SEric Christopher; CHECK-NEXT:    xor
112cee313d2SEric Christopherentry:
113*d9e51e75SMatt Arsenault  %tmp = load i8, ptr @a, align 1
114cee313d2SEric Christopher  %xor = xor i8 %tmp, 60
115cee313d2SEric Christopher  %cmp = icmp ugt i8 %xor, 20
116cee313d2SEric Christopher  br i1 %cmp, label %if.then, label %if.end
117cee313d2SEric Christopher
118cee313d2SEric Christopherif.then:                                          ; preds = %entry
119cee313d2SEric Christopher  %conv2 = zext i8 %xor to i32
120cee313d2SEric Christopher  %add = add nsw i32 %conv2, %ll
121*d9e51e75SMatt Arsenault  store i32 %add, ptr %p, align 4
122cee313d2SEric Christopher  br label %if.end
123cee313d2SEric Christopher
124cee313d2SEric Christopherif.end:                                           ; preds = %if.then, %entry
125cee313d2SEric Christopher  tail call void @foo()
126cee313d2SEric Christopher  ret void
127cee313d2SEric Christopher}
128cee313d2SEric Christopher
129