brintos

brintos / llvm-project-archived public Read only

0
0
Text · 6.8 KiB · f9454c4 Raw
230 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py2; RUN: llc -mtriple=i686-unknown-linux-gnu             < %s | FileCheck %s   --check-prefixes=X86,NOBMI-X863; RUN: llc -mtriple=i686-unknown-linux-gnu -mattr=+bmi < %s | FileCheck %s   --check-prefixes=X86,BMI-X864; RUN: llc -mtriple=x86_64-unknown-linux-gnu             < %s | FileCheck %s --check-prefixes=X64,NOBMI-X645; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=+bmi < %s | FileCheck %s --check-prefixes=X64,BMI-X646 7; Fold8;   ptr - (ptr & mask)9; To10;   ptr & (~mask)11;12; This needs to be a backend-level fold because only by now pointers13; are just registers; in middle-end IR this can only be done via @llvm.ptrmask()14; intrinsic which is not sufficiently widely-spread yet.15;16; https://bugs.llvm.org/show_bug.cgi?id=4444817 18; The basic positive tests19 20define i32 @t0_32(i32 %ptr, i32 %mask) nounwind {21; NOBMI-X86-LABEL: t0_32:22; NOBMI-X86:       # %bb.0:23; NOBMI-X86-NEXT:    movl {{[0-9]+}}(%esp), %eax24; NOBMI-X86-NEXT:    notl %eax25; NOBMI-X86-NEXT:    andl {{[0-9]+}}(%esp), %eax26; NOBMI-X86-NEXT:    retl27;28; BMI-X86-LABEL: t0_32:29; BMI-X86:       # %bb.0:30; BMI-X86-NEXT:    movl {{[0-9]+}}(%esp), %eax31; BMI-X86-NEXT:    andnl {{[0-9]+}}(%esp), %eax, %eax32; BMI-X86-NEXT:    retl33;34; NOBMI-X64-LABEL: t0_32:35; NOBMI-X64:       # %bb.0:36; NOBMI-X64-NEXT:    movl %esi, %eax37; NOBMI-X64-NEXT:    notl %eax38; NOBMI-X64-NEXT:    andl %edi, %eax39; NOBMI-X64-NEXT:    retq40;41; BMI-X64-LABEL: t0_32:42; BMI-X64:       # %bb.0:43; BMI-X64-NEXT:    andnl %edi, %esi, %eax44; BMI-X64-NEXT:    retq45  %bias = and i32 %ptr, %mask46  %r = sub i32 %ptr, %bias47  ret i32 %r48}49define i64 @t1_64(i64 %ptr, i64 %mask) nounwind {50; NOBMI-X86-LABEL: t1_64:51; NOBMI-X86:       # %bb.0:52; NOBMI-X86-NEXT:    movl {{[0-9]+}}(%esp), %eax53; NOBMI-X86-NEXT:    movl {{[0-9]+}}(%esp), %edx54; NOBMI-X86-NEXT:    notl %eax55; NOBMI-X86-NEXT:    andl {{[0-9]+}}(%esp), %eax56; NOBMI-X86-NEXT:    notl %edx57; NOBMI-X86-NEXT:    andl {{[0-9]+}}(%esp), %edx58; NOBMI-X86-NEXT:    retl59;60; BMI-X86-LABEL: t1_64:61; BMI-X86:       # %bb.0:62; BMI-X86-NEXT:    movl {{[0-9]+}}(%esp), %eax63; BMI-X86-NEXT:    movl {{[0-9]+}}(%esp), %ecx64; BMI-X86-NEXT:    andnl {{[0-9]+}}(%esp), %eax, %eax65; BMI-X86-NEXT:    andnl {{[0-9]+}}(%esp), %ecx, %edx66; BMI-X86-NEXT:    retl67;68; NOBMI-X64-LABEL: t1_64:69; NOBMI-X64:       # %bb.0:70; NOBMI-X64-NEXT:    movq %rsi, %rax71; NOBMI-X64-NEXT:    notq %rax72; NOBMI-X64-NEXT:    andq %rdi, %rax73; NOBMI-X64-NEXT:    retq74;75; BMI-X64-LABEL: t1_64:76; BMI-X64:       # %bb.0:77; BMI-X64-NEXT:    andnq %rdi, %rsi, %rax78; BMI-X64-NEXT:    retq79  %bias = and i64 %ptr, %mask80  %r = sub i64 %ptr, %bias81  ret i64 %r82}83 84define i32 @t2_commutative(i32 %ptr, i32 %mask) nounwind {85; NOBMI-X86-LABEL: t2_commutative:86; NOBMI-X86:       # %bb.0:87; NOBMI-X86-NEXT:    movl {{[0-9]+}}(%esp), %eax88; NOBMI-X86-NEXT:    notl %eax89; NOBMI-X86-NEXT:    andl {{[0-9]+}}(%esp), %eax90; NOBMI-X86-NEXT:    retl91;92; BMI-X86-LABEL: t2_commutative:93; BMI-X86:       # %bb.0:94; BMI-X86-NEXT:    movl {{[0-9]+}}(%esp), %eax95; BMI-X86-NEXT:    andnl {{[0-9]+}}(%esp), %eax, %eax96; BMI-X86-NEXT:    retl97;98; NOBMI-X64-LABEL: t2_commutative:99; NOBMI-X64:       # %bb.0:100; NOBMI-X64-NEXT:    movl %esi, %eax101; NOBMI-X64-NEXT:    notl %eax102; NOBMI-X64-NEXT:    andl %edi, %eax103; NOBMI-X64-NEXT:    retq104;105; BMI-X64-LABEL: t2_commutative:106; BMI-X64:       # %bb.0:107; BMI-X64-NEXT:    andnl %edi, %esi, %eax108; BMI-X64-NEXT:    retq109  %bias = and i32 %mask, %ptr ; swapped110  %r = sub i32 %ptr, %bias111  ret i32 %r112}113 114; Extra use tests115 116define i32 @n3_extrause1(i32 %ptr, i32 %mask, ptr %bias_storage) nounwind {117; X86-LABEL: n3_extrause1:118; X86:       # %bb.0:119; X86-NEXT:    movl {{[0-9]+}}(%esp), %ecx120; X86-NEXT:    movl {{[0-9]+}}(%esp), %eax121; X86-NEXT:    movl {{[0-9]+}}(%esp), %edx122; X86-NEXT:    andl %eax, %edx123; X86-NEXT:    movl %edx, (%ecx)124; X86-NEXT:    subl %edx, %eax125; X86-NEXT:    retl126;127; X64-LABEL: n3_extrause1:128; X64:       # %bb.0:129; X64-NEXT:    movl %edi, %eax130; X64-NEXT:    andl %edi, %esi131; X64-NEXT:    movl %esi, (%rdx)132; X64-NEXT:    subl %esi, %eax133; X64-NEXT:    retq134  %bias = and i32 %ptr, %mask ; has extra uses, can't fold135  store i32 %bias, ptr %bias_storage136  %r = sub i32 %ptr, %bias137  ret i32 %r138}139 140; Negative tests141 142define i32 @n4_different_ptrs(i32 %ptr0, i32 %ptr1, i32 %mask) nounwind {143; X86-LABEL: n4_different_ptrs:144; X86:       # %bb.0:145; X86-NEXT:    movl {{[0-9]+}}(%esp), %eax146; X86-NEXT:    movl {{[0-9]+}}(%esp), %ecx147; X86-NEXT:    andl {{[0-9]+}}(%esp), %ecx148; X86-NEXT:    subl %ecx, %eax149; X86-NEXT:    retl150;151; X64-LABEL: n4_different_ptrs:152; X64:       # %bb.0:153; X64-NEXT:    movl %edi, %eax154; X64-NEXT:    andl %edx, %esi155; X64-NEXT:    subl %esi, %eax156; X64-NEXT:    retq157  %bias = and i32 %ptr1, %mask ; not %ptr0158  %r = sub i32 %ptr0, %bias ; not %ptr1159  ret i32 %r160}161define i32 @n5_different_ptrs_commutative(i32 %ptr0, i32 %ptr1, i32 %mask) nounwind {162; X86-LABEL: n5_different_ptrs_commutative:163; X86:       # %bb.0:164; X86-NEXT:    movl {{[0-9]+}}(%esp), %eax165; X86-NEXT:    movl {{[0-9]+}}(%esp), %ecx166; X86-NEXT:    andl {{[0-9]+}}(%esp), %ecx167; X86-NEXT:    subl %ecx, %eax168; X86-NEXT:    retl169;170; X64-LABEL: n5_different_ptrs_commutative:171; X64:       # %bb.0:172; X64-NEXT:    movl %edi, %eax173; X64-NEXT:    andl %edx, %esi174; X64-NEXT:    subl %esi, %eax175; X64-NEXT:    retq176  %bias = and i32 %mask, %ptr1 ; swapped, not %ptr0177  %r = sub i32 %ptr0, %bias ; not %ptr1178  ret i32 %r179}180 181define i32 @n6_not_lowbit_mask(i32 %ptr, i32 %mask) nounwind {182; NOBMI-X86-LABEL: n6_not_lowbit_mask:183; NOBMI-X86:       # %bb.0:184; NOBMI-X86-NEXT:    movl {{[0-9]+}}(%esp), %eax185; NOBMI-X86-NEXT:    notl %eax186; NOBMI-X86-NEXT:    andl {{[0-9]+}}(%esp), %eax187; NOBMI-X86-NEXT:    retl188;189; BMI-X86-LABEL: n6_not_lowbit_mask:190; BMI-X86:       # %bb.0:191; BMI-X86-NEXT:    movl {{[0-9]+}}(%esp), %eax192; BMI-X86-NEXT:    andnl {{[0-9]+}}(%esp), %eax, %eax193; BMI-X86-NEXT:    retl194;195; NOBMI-X64-LABEL: n6_not_lowbit_mask:196; NOBMI-X64:       # %bb.0:197; NOBMI-X64-NEXT:    movl %esi, %eax198; NOBMI-X64-NEXT:    notl %eax199; NOBMI-X64-NEXT:    andl %edi, %eax200; NOBMI-X64-NEXT:    retq201;202; BMI-X64-LABEL: n6_not_lowbit_mask:203; BMI-X64:       # %bb.0:204; BMI-X64-NEXT:    andnl %edi, %esi, %eax205; BMI-X64-NEXT:    retq206  %bias = and i32 %ptr, %mask207  %r = sub i32 %ptr, %bias208  ret i32 %r209}210 211define i32 @n7_sub_is_not_commutative(i32 %ptr, i32 %mask) nounwind {212; X86-LABEL: n7_sub_is_not_commutative:213; X86:       # %bb.0:214; X86-NEXT:    movl {{[0-9]+}}(%esp), %ecx215; X86-NEXT:    movl {{[0-9]+}}(%esp), %eax216; X86-NEXT:    andl %ecx, %eax217; X86-NEXT:    subl %ecx, %eax218; X86-NEXT:    retl219;220; X64-LABEL: n7_sub_is_not_commutative:221; X64:       # %bb.0:222; X64-NEXT:    movl %esi, %eax223; X64-NEXT:    andl %edi, %eax224; X64-NEXT:    subl %edi, %eax225; X64-NEXT:    retq226  %bias = and i32 %ptr, %mask227  %r = sub i32 %bias, %ptr ; wrong order228  ret i32 %r229}230