1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 2; RUN: llc -verify-machineinstrs -mtriple=powerpc-unknown-linux-gnu -mcpu=ppc64 < %s | FileCheck -check-prefixes=CHECK,CHECK64 %s 3; RUN: llc -verify-machineinstrs -mtriple=powerpc-unknown-linux-gnu -mcpu=ppc < %s | FileCheck -check-prefixes=CHECK,CHECK32 %s 4 5define i32 @fold_urem_positive_odd(i32 %x) { 6; CHECK-LABEL: fold_urem_positive_odd: 7; CHECK: # %bb.0: 8; CHECK-NEXT: lis 4, 22765 9; CHECK-NEXT: ori 4, 4, 8969 10; CHECK-NEXT: mulhwu 4, 3, 4 11; CHECK-NEXT: sub 5, 3, 4 12; CHECK-NEXT: srwi 5, 5, 1 13; CHECK-NEXT: add 4, 5, 4 14; CHECK-NEXT: srwi 4, 4, 6 15; CHECK-NEXT: mulli 4, 4, 95 16; CHECK-NEXT: sub 3, 3, 4 17; CHECK-NEXT: blr 18 %1 = urem i32 %x, 95 19 ret i32 %1 20} 21 22 23define i32 @fold_urem_positive_even(i32 %x) { 24; CHECK-LABEL: fold_urem_positive_even: 25; CHECK: # %bb.0: 26; CHECK-NEXT: lis 4, -2226 27; CHECK-NEXT: ori 4, 4, 16323 28; CHECK-NEXT: mulhwu 4, 3, 4 29; CHECK-NEXT: srwi 4, 4, 10 30; CHECK-NEXT: mulli 4, 4, 1060 31; CHECK-NEXT: sub 3, 3, 4 32; CHECK-NEXT: blr 33 %1 = urem i32 %x, 1060 34 ret i32 %1 35} 36 37 38; Don't fold if we can combine urem with udiv. 39define i32 @combine_urem_udiv(i32 %x) { 40; CHECK-LABEL: combine_urem_udiv: 41; CHECK: # %bb.0: 42; CHECK-NEXT: lis 4, 22765 43; CHECK-NEXT: ori 4, 4, 8969 44; CHECK-NEXT: mulhwu 4, 3, 4 45; CHECK-NEXT: sub 5, 3, 4 46; CHECK-NEXT: srwi 5, 5, 1 47; CHECK-NEXT: add 4, 5, 4 48; CHECK-NEXT: srwi 4, 4, 6 49; CHECK-NEXT: mulli 5, 4, 95 50; CHECK-NEXT: sub 3, 3, 5 51; CHECK-NEXT: add 3, 3, 4 52; CHECK-NEXT: blr 53 %1 = urem i32 %x, 95 54 %2 = udiv i32 %x, 95 55 %3 = add i32 %1, %2 56 ret i32 %3 57} 58 59; Don't fold for divisors that are a power of two. 60define i32 @dont_fold_urem_power_of_two(i32 %x) { 61; CHECK-LABEL: dont_fold_urem_power_of_two: 62; CHECK: # %bb.0: 63; CHECK-NEXT: clrlwi 3, 3, 26 64; CHECK-NEXT: blr 65 %1 = urem i32 %x, 64 66 ret i32 %1 67} 68 69; Don't fold if the divisor is one. 70define i32 @dont_fold_urem_one(i32 %x) { 71; CHECK-LABEL: dont_fold_urem_one: 72; CHECK: # %bb.0: 73; CHECK-NEXT: li 3, 0 74; CHECK-NEXT: blr 75 %1 = urem i32 %x, 1 76 ret i32 %1 77} 78 79; Don't fold if the divisor is 2^32. 80define i32 @dont_fold_urem_i32_umax(i32 %x) { 81; CHECK-LABEL: dont_fold_urem_i32_umax: 82; CHECK: # %bb.0: 83; CHECK-NEXT: blr 84 %1 = urem i32 %x, 4294967296 85 ret i32 %1 86} 87 88; Don't fold i64 urem 89define i64 @dont_fold_urem_i64(i64 %x) { 90; CHECK-LABEL: dont_fold_urem_i64: 91; CHECK: # %bb.0: 92; CHECK-NEXT: mflr 0 93; CHECK-NEXT: stw 0, 4(1) 94; CHECK-NEXT: stwu 1, -16(1) 95; CHECK-NEXT: .cfi_def_cfa_offset 16 96; CHECK-NEXT: .cfi_offset lr, 4 97; CHECK-NEXT: li 5, 0 98; CHECK-NEXT: li 6, 98 99; CHECK-NEXT: bl __umoddi3 100; CHECK-NEXT: lwz 0, 20(1) 101; CHECK-NEXT: addi 1, 1, 16 102; CHECK-NEXT: mtlr 0 103; CHECK-NEXT: blr 104 %1 = urem i64 %x, 98 105 ret i64 %1 106} 107