Skip to content

Commit

Permalink
[ARM] GlobalISel: Support G_OR
Browse files Browse the repository at this point in the history
Same as the other binary operators:
- legalize to 32 bits
- map to GPRs
- select ORRrr thanks to TableGen'erated code

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@304890 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
rovka committed Jun 7, 2017
1 parent a7783d7 commit acf8740
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Target/ARM/ARMLegalizerInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ ARMLegalizerInfo::ARMLegalizerInfo(const ARMSubtarget &ST) {
setAction({Op, 1, p0}, Legal);
}

for (unsigned Op : {G_ADD, G_SUB, G_MUL, G_AND}) {
for (unsigned Op : {G_ADD, G_SUB, G_MUL, G_AND, G_OR}) {
for (auto Ty : {s1, s8, s16})
setAction({Op, Ty}, WidenScalar);
setAction({Op, s32}, Legal);
Expand Down
1 change: 1 addition & 0 deletions lib/Target/ARM/ARMRegisterBankInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ ARMRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
case G_SUB:
case G_MUL:
case G_AND:
case G_OR:
case G_SDIV:
case G_UDIV:
case G_SEXT:
Expand Down
34 changes: 34 additions & 0 deletions test/CodeGen/ARM/GlobalISel/arm-instruction-select.mir
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
define void @test_udiv_s32() #2 { ret void }

define void @test_and_s32() { ret void }
define void @test_or_s32() { ret void }

define void @test_load_from_stack() { ret void }
define void @test_load_f32() #0 { ret void }
Expand Down Expand Up @@ -818,6 +819,39 @@ body: |
; CHECK: BX_RET 14, _, implicit %r0
...
---
name: test_or_s32
# CHECK-LABEL: name: test_or_s32
legalized: true
regBankSelected: true
selected: false
# CHECK: selected: true
registers:
- { id: 0, class: gprb }
- { id: 1, class: gprb }
- { id: 2, class: gprb }
# CHECK: id: 0, class: gpr
# CHECK: id: 1, class: gpr
# CHECK: id: 2, class: gpr
body: |
bb.0:
liveins: %r0, %r1
%0(s32) = COPY %r0
; CHECK: [[VREGX:%[0-9]+]] = COPY %r0
%1(s32) = COPY %r1
; CHECK: [[VREGY:%[0-9]+]] = COPY %r1
%2(s32) = G_OR %0, %1
; CHECK: [[VREGRES:%[0-9]+]] = ORRrr [[VREGX]], [[VREGY]], 14, _
%r0 = COPY %2(s32)
; CHECK: %r0 = COPY [[VREGRES]]
BX_RET 14, _, implicit %r0
; CHECK: BX_RET 14, _, implicit %r0
...
---
name: test_load_from_stack
# CHECK-LABEL: name: test_load_from_stack
legalized: true
Expand Down
27 changes: 27 additions & 0 deletions test/CodeGen/ARM/GlobalISel/arm-isel.ll
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,33 @@ entry:
ret i32 %sum
}

define i8 @test_or_i8(i8 %x, i8 %y) {
; CHECK-LABEL: test_or_i8:
; CHECK: orr r0, r0, r1
; CHECK: bx lr
entry:
%sum = or i8 %x, %y
ret i8 %sum
}

define i16 @test_or_i16(i16 %x, i16 %y) {
; CHECK-LABEL: test_or_i16:
; CHECK: orr r0, r0, r1
; CHECK: bx lr
entry:
%sum = or i16 %x, %y
ret i16 %sum
}

define i32 @test_or_i32(i32 %x, i32 %y) {
; CHECK-LABEL: test_or_i32:
; CHECK: orr r0, r0, r1
; CHECK: bx lr
entry:
%sum = or i32 %x, %y
ret i32 %sum
}

define i32 @test_stack_args_i32(i32 %p0, i32 %p1, i32 %p2, i32 %p3, i32 %p4, i32 %p5) {
; CHECK-LABEL: test_stack_args_i32:
; CHECK: add [[P5ADDR:r[0-9]+]], sp, #4
Expand Down
80 changes: 80 additions & 0 deletions test/CodeGen/ARM/GlobalISel/arm-legalizer.mir
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
define void @test_and_s16() { ret void }
define void @test_and_s32() { ret void }

define void @test_or_s8() { ret void }
define void @test_or_s16() { ret void }
define void @test_or_s32() { ret void }

define void @test_load_from_stack() { ret void }
define void @test_legal_loads() #0 { ret void }
define void @test_legal_stores() #0 { ret void }
Expand Down Expand Up @@ -379,6 +383,82 @@ body: |
%r0 = COPY %2(s32)
BX_RET 14, _, implicit %r0
...
---
name: test_or_s8
# CHECK-LABEL: name: test_or_s8
legalized: false
# CHECK: legalized: true
regBankSelected: false
selected: false
tracksRegLiveness: true
registers:
- { id: 0, class: _ }
- { id: 1, class: _ }
- { id: 2, class: _ }
body: |
bb.0:
liveins: %r0, %r1
%0(s8) = COPY %r0
%1(s8) = COPY %r1
%2(s8) = G_OR %0, %1
; G_OR with s8 should widen
; CHECK: {{%[0-9]+}}(s32) = G_OR {{%[0-9]+, %[0-9]+}}
; CHECK-NOT: {{%[0-9]+}}(s8) = G_OR {{%[0-9]+, %[0-9]+}}
%r0 = COPY %2(s8)
BX_RET 14, _, implicit %r0
...
---
name: test_or_s16
# CHECK-LABEL: name: test_or_s16
legalized: false
# CHECK: legalized: true
regBankSelected: false
selected: false
tracksRegLiveness: true
registers:
- { id: 0, class: _ }
- { id: 1, class: _ }
- { id: 2, class: _ }
body: |
bb.0:
liveins: %r0, %r1
%0(s16) = COPY %r0
%1(s16) = COPY %r1
%2(s16) = G_OR %0, %1
; G_OR with s16 should widen
; CHECK: {{%[0-9]+}}(s32) = G_OR {{%[0-9]+, %[0-9]+}}
; CHECK-NOT: {{%[0-9]+}}(s16) = G_OR {{%[0-9]+, %[0-9]+}}
%r0 = COPY %2(s16)
BX_RET 14, _, implicit %r0
...
---
name: test_or_s32
# CHECK-LABEL: name: test_or_s32
legalized: false
# CHECK: legalized: true
regBankSelected: false
selected: false
tracksRegLiveness: true
registers:
- { id: 0, class: _ }
- { id: 1, class: _ }
- { id: 2, class: _ }
body: |
bb.0:
liveins: %r0, %r1
%0(s32) = COPY %r0
%1(s32) = COPY %r1
%2(s32) = G_OR %0, %1
; G_OR with s32 is legal, so we should find it unchanged in the output
; CHECK: {{%[0-9]+}}(s32) = G_OR {{%[0-9]+, %[0-9]+}}
%r0 = COPY %2(s32)
BX_RET 14, _, implicit %r0
...
---
name: test_load_from_stack
Expand Down
27 changes: 27 additions & 0 deletions test/CodeGen/ARM/GlobalISel/arm-regbankselect.mir
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
define void @test_udiv_s32() #1 { ret void }

define void @test_and_s32() { ret void}
define void @test_or_s32() { ret void}

define void @test_loads() #0 { ret void }
define void @test_stores() #0 { ret void }
Expand Down Expand Up @@ -440,6 +441,32 @@ body: |
%r0 = COPY %2(s32)
BX_RET 14, _, implicit %r0
...
---
name: test_or_s32
# CHECK-LABEL: name: test_or_s32
legalized: true
regBankSelected: false
selected: false
# CHECK: registers:
# CHECK: - { id: 0, class: gprb, preferred-register: '' }
# CHECK: - { id: 1, class: gprb, preferred-register: '' }
# CHECK: - { id: 2, class: gprb, preferred-register: '' }

registers:
- { id: 0, class: _ }
- { id: 1, class: _ }
- { id: 2, class: _ }
body: |
bb.0:
liveins: %r0, %r1
%0(s32) = COPY %r0
%1(s32) = COPY %r1
%2(s32) = G_OR %0, %1
%r0 = COPY %2(s32)
BX_RET 14, _, implicit %r0
...
---
name: test_loads
Expand Down

0 comments on commit acf8740

Please sign in to comment.