1; RUN: llc -mtriple=armv7a -mattr=+hwdiv-arm %s -o - | FileCheck %s --check-prefixes=CHECK,DIV 2; RUN: llc -mtriple=armv7a -mattr=-hwdiv-arm %s -o - | FileCheck %s --check-prefixes=CHECK,NODIV 3 4; Check SREM 5define dso_local i32 @test_rem(i32 %F) local_unnamed_addr #0 { 6; CHECK-LABEL: test_rem 7; CHECK: asr r1, r0, #31 8; CHECK-NEXT: add r1, r0, r1, lsr #30 9; CHECK-NEXT: bic r1, r1, #3 10; CHECK-NEXT: sub r0, r0, r1 11 12entry: 13 %div = srem i32 %F, 4 14 ret i32 %div 15} 16 17; Try an i16 sdiv, with a small immediate. 18define dso_local signext i16 @f0(i16 signext %F) local_unnamed_addr #0 { 19; CHECK-LABEL: f0 20 21; DIV: mov r1, #2 22; DIV-NEXT: sdiv r0, r0, r1 23; DIV-NEXT: sxth r0, r0 24; DIV-NEXT: bx lr 25 26; NODIV: uxth r1, r0 27; NODIV-NEXT: add r0, r0, r1, lsr #15 28; NODIV-NEXT: sxth r0, r0 29; NODIV-NEXT: asr r0, r0, #1 30; NODIV-NEXT: bx lr 31 32entry: 33 %0 = sdiv i16 %F, 2 34 ret i16 %0 35} 36 37; Try an i32 sdiv, with a small immediate. 38define dso_local i32 @f1(i32 %F) local_unnamed_addr #0 { 39; CHECK-LABEL: f1 40 41; DIV: mov r1, #4 42; DIV-NEXT: sdiv r0, r0, r1 43; DIV-NEXT: bx lr 44 45; NODIV: asr r1, r0, #31 46; NODIV-NEXT: add r0, r0, r1, lsr #30 47; NODIV-NEXT: asr r0, r0, #2 48; NODIV-NEXT: bx lr 49 50entry: 51 %div = sdiv i32 %F, 4 52 ret i32 %div 53} 54 55; Try a large power of 2 immediate, which should also be materialised with 1 56; move immediate instruction. 57define dso_local i32 @f2(i32 %F) local_unnamed_addr #0 { 58; CHECK-LABEL: f2 59; DIV: mov r1, #131072 60; DIV-NEXT: sdiv r0, r0, r1 61; DIV-NEXT: bx lr 62entry: 63 %div = sdiv i32 %F, 131072 64 ret i32 %div 65} 66 67; MinSize not set, so should expand to the faster but longer sequence. 68define dso_local i32 @f3(i32 %F) { 69; CHECK-LABEL: f3 70; CHECK: asr r1, r0, #31 71; CHECK-NEXT: add r0, r0, r1, lsr #30 72; CHECK-NEXT: asr r0, r0, #2 73; CHECK-NEXT: bx lr 74entry: 75 %div = sdiv i32 %F, 4 76 ret i32 %div 77} 78 79attributes #0 = { minsize norecurse nounwind optsize readnone } 80