353 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py2; RUN: llc < %s -mtriple=i686-linux | FileCheck %s --check-prefixes=X863; RUN: llc < %s -mtriple=x86_64-linux | FileCheck %s --check-prefixes=X644 5declare void @use(i8)6 7define i8 @add_and_xor(i8 %x, i8 %y) {8; X86-LABEL: add_and_xor:9; X86: # %bb.0:10; X86-NEXT: movzbl {{[0-9]+}}(%esp), %eax11; X86-NEXT: orb {{[0-9]+}}(%esp), %al12; X86-NEXT: retl13;14; X64-LABEL: add_and_xor:15; X64: # %bb.0:16; X64-NEXT: movl %edi, %eax17; X64-NEXT: orl %esi, %eax18; X64-NEXT: # kill: def $al killed $al killed $eax19; X64-NEXT: retq20 %xor = xor i8 %x, -121 %and = and i8 %xor, %y22 %add = add i8 %and, %x23 ret i8 %add24}25 26define i8 @add_and_xor_wrong_const(i8 %x, i8 %y) {27; X86-LABEL: add_and_xor_wrong_const:28; X86: # %bb.0:29; X86-NEXT: movzbl {{[0-9]+}}(%esp), %ecx30; X86-NEXT: movl %ecx, %eax31; X86-NEXT: xorb $-2, %al32; X86-NEXT: andb {{[0-9]+}}(%esp), %al33; X86-NEXT: addb %cl, %al34; X86-NEXT: retl35;36; X64-LABEL: add_and_xor_wrong_const:37; X64: # %bb.0:38; X64-NEXT: movl %edi, %eax39; X64-NEXT: xorb $-2, %al40; X64-NEXT: andb %sil, %al41; X64-NEXT: addb %dil, %al42; X64-NEXT: retq43 %xor = xor i8 %x, -244 %and = and i8 %xor, %y45 %add = add i8 %and, %x46 ret i8 %add47}48 49define i8 @add_and_xor_wrong_op(i8 %x, i8 %y, i8 %z) {50; X86-LABEL: add_and_xor_wrong_op:51; X86: # %bb.0:52; X86-NEXT: movzbl {{[0-9]+}}(%esp), %eax53; X86-NEXT: notb %al54; X86-NEXT: andb {{[0-9]+}}(%esp), %al55; X86-NEXT: addb {{[0-9]+}}(%esp), %al56; X86-NEXT: retl57;58; X64-LABEL: add_and_xor_wrong_op:59; X64: # %bb.0:60; X64-NEXT: # kill: def $edx killed $edx def $rdx61; X64-NEXT: # kill: def $edi killed $edi def $rdi62; X64-NEXT: notb %dl63; X64-NEXT: andb %sil, %dl64; X64-NEXT: leal (%rdx,%rdi), %eax65; X64-NEXT: # kill: def $al killed $al killed $eax66; X64-NEXT: retq67 %xor = xor i8 %z, -168 %and = and i8 %xor, %y69 %add = add i8 %and, %x70 ret i8 %add71}72 73define i8 @add_and_xor_commuted1(i8 %x, i8 %y) {74; X86-LABEL: add_and_xor_commuted1:75; X86: # %bb.0:76; X86-NEXT: movzbl {{[0-9]+}}(%esp), %eax77; X86-NEXT: orb {{[0-9]+}}(%esp), %al78; X86-NEXT: retl79;80; X64-LABEL: add_and_xor_commuted1:81; X64: # %bb.0:82; X64-NEXT: movl %edi, %eax83; X64-NEXT: orl %esi, %eax84; X64-NEXT: # kill: def $al killed $al killed $eax85; X64-NEXT: retq86 %xor = xor i8 %x, -187 %and = and i8 %y, %xor88 %add = add i8 %and, %x89 ret i8 %add90}91 92define i8 @add_and_xor_commuted2(i8 %x, i8 %y) {93; X86-LABEL: add_and_xor_commuted2:94; X86: # %bb.0:95; X86-NEXT: movzbl {{[0-9]+}}(%esp), %eax96; X86-NEXT: orb {{[0-9]+}}(%esp), %al97; X86-NEXT: retl98;99; X64-LABEL: add_and_xor_commuted2:100; X64: # %bb.0:101; X64-NEXT: movl %edi, %eax102; X64-NEXT: orl %esi, %eax103; X64-NEXT: # kill: def $al killed $al killed $eax104; X64-NEXT: retq105 %xor = xor i8 %x, -1106 %and = and i8 %xor, %y107 %add = add i8 %x, %and108 ret i8 %add109}110 111define i8 @add_and_xor_commuted3(i8 %x, i8 %y) {112; X86-LABEL: add_and_xor_commuted3:113; X86: # %bb.0:114; X86-NEXT: movzbl {{[0-9]+}}(%esp), %eax115; X86-NEXT: orb {{[0-9]+}}(%esp), %al116; X86-NEXT: retl117;118; X64-LABEL: add_and_xor_commuted3:119; X64: # %bb.0:120; X64-NEXT: movl %edi, %eax121; X64-NEXT: orl %esi, %eax122; X64-NEXT: # kill: def $al killed $al killed $eax123; X64-NEXT: retq124 %xor = xor i8 %x, -1125 %and = and i8 %y, %xor126 %add = add i8 %x, %and127 ret i8 %add128}129 130define i8 @add_and_xor_extra_use(i8 %x, i8 %y) nounwind {131; X86-LABEL: add_and_xor_extra_use:132; X86: # %bb.0:133; X86-NEXT: pushl %ebx134; X86-NEXT: subl $8, %esp135; X86-NEXT: movzbl {{[0-9]+}}(%esp), %ebx136; X86-NEXT: movb {{[0-9]+}}(%esp), %bh137; X86-NEXT: notb %bh138; X86-NEXT: movzbl %bh, %eax139; X86-NEXT: movl %eax, (%esp)140; X86-NEXT: calll use@PLT141; X86-NEXT: andb %bl, %bh142; X86-NEXT: movzbl %bh, %eax143; X86-NEXT: movl %eax, (%esp)144; X86-NEXT: calll use@PLT145; X86-NEXT: orb {{[0-9]+}}(%esp), %bl146; X86-NEXT: movl %ebx, %eax147; X86-NEXT: addl $8, %esp148; X86-NEXT: popl %ebx149; X86-NEXT: retl150;151; X64-LABEL: add_and_xor_extra_use:152; X64: # %bb.0:153; X64-NEXT: pushq %rbp154; X64-NEXT: pushq %r14155; X64-NEXT: pushq %rbx156; X64-NEXT: movl %esi, %ebx157; X64-NEXT: movl %edi, %ebp158; X64-NEXT: movl %ebp, %eax159; X64-NEXT: notb %al160; X64-NEXT: movzbl %al, %r14d161; X64-NEXT: movl %r14d, %edi162; X64-NEXT: callq use@PLT163; X64-NEXT: andb %bl, %r14b164; X64-NEXT: movzbl %r14b, %edi165; X64-NEXT: callq use@PLT166; X64-NEXT: orb %bpl, %bl167; X64-NEXT: movl %ebx, %eax168; X64-NEXT: popq %rbx169; X64-NEXT: popq %r14170; X64-NEXT: popq %rbp171; X64-NEXT: retq172 %xor = xor i8 %x, -1173 call void @use(i8 %xor)174 %and = and i8 %xor, %y175 call void @use(i8 %and)176 %add = add i8 %and, %x177 ret i8 %add178}179 180define i64 @add_and_xor_const(i64 %x) {181; X86-LABEL: add_and_xor_const:182; X86: # %bb.0:183; X86-NEXT: movl {{[0-9]+}}(%esp), %eax184; X86-NEXT: movl {{[0-9]+}}(%esp), %edx185; X86-NEXT: orl $1, %eax186; X86-NEXT: retl187;188; X64-LABEL: add_and_xor_const:189; X64: # %bb.0:190; X64-NEXT: movq %rdi, %rax191; X64-NEXT: orq $1, %rax192; X64-NEXT: retq193 %xor = xor i64 %x, -1194 %and = and i64 %xor, 1195 %add = add i64 %and, %x196 ret i64 %add197}198 199define i64 @add_and_xor_const_wrong_op(i64 %x, i64 %y) {200; X86-LABEL: add_and_xor_const_wrong_op:201; X86: # %bb.0:202; X86-NEXT: movl {{[0-9]+}}(%esp), %edx203; X86-NEXT: movl {{[0-9]+}}(%esp), %eax204; X86-NEXT: notl %eax205; X86-NEXT: andl $1, %eax206; X86-NEXT: addl {{[0-9]+}}(%esp), %eax207; X86-NEXT: adcl $0, %edx208; X86-NEXT: retl209;210; X64-LABEL: add_and_xor_const_wrong_op:211; X64: # %bb.0:212; X64-NEXT: notl %esi213; X64-NEXT: andl $1, %esi214; X64-NEXT: leaq (%rsi,%rdi), %rax215; X64-NEXT: retq216 %xor = xor i64 %y, -1217 %and = and i64 %xor, 1218 %add = add i64 %and, %x219 ret i64 %add220}221 222define i64 @add_and_xor_const_explicit_trunc(i64 %x) {223; X86-LABEL: add_and_xor_const_explicit_trunc:224; X86: # %bb.0:225; X86-NEXT: movl {{[0-9]+}}(%esp), %eax226; X86-NEXT: movl {{[0-9]+}}(%esp), %edx227; X86-NEXT: orl $1, %eax228; X86-NEXT: retl229;230; X64-LABEL: add_and_xor_const_explicit_trunc:231; X64: # %bb.0:232; X64-NEXT: movq %rdi, %rax233; X64-NEXT: orq $1, %rax234; X64-NEXT: retq235 %trunc = trunc i64 %x to i32236 %xor = xor i32 %trunc, -1237 %ext = sext i32 %xor to i64238 %and = and i64 %ext, 1239 %add = add i64 %and, %x240 ret i64 %add241}242 243define i64 @add_and_xor_const_explicit_trunc_wrong_mask(i64 %x) {244; X86-LABEL: add_and_xor_const_explicit_trunc_wrong_mask:245; X86: # %bb.0:246; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx247; X86-NEXT: movl %ecx, %eax248; X86-NEXT: notl %eax249; X86-NEXT: movl %eax, %edx250; X86-NEXT: shrl $31, %edx251; X86-NEXT: andl $1, %eax252; X86-NEXT: addl %ecx, %eax253; X86-NEXT: adcl {{[0-9]+}}(%esp), %edx254; X86-NEXT: retl255;256; X64-LABEL: add_and_xor_const_explicit_trunc_wrong_mask:257; X64: # %bb.0:258; X64-NEXT: movl %edi, %eax259; X64-NEXT: notl %eax260; X64-NEXT: movslq %eax, %rcx261; X64-NEXT: movabsq $4294967297, %rax # imm = 0x100000001262; X64-NEXT: andq %rcx, %rax263; X64-NEXT: addq %rdi, %rax264; X64-NEXT: retq265 %trunc = trunc i64 %x to i32266 %xor = xor i32 %trunc, -1267 %ext = sext i32 %xor to i64268 %and = and i64 %ext, 4294967297269 %add = add i64 %and, %x270 ret i64 %add271}272 273define ptr @gep_and_xor(ptr %a, i64 %m) {274; X86-LABEL: gep_and_xor:275; X86: # %bb.0:276; X86-NEXT: movl {{[0-9]+}}(%esp), %eax277; X86-NEXT: orl {{[0-9]+}}(%esp), %eax278; X86-NEXT: retl279;280; X64-LABEL: gep_and_xor:281; X64: # %bb.0:282; X64-NEXT: movq %rdi, %rax283; X64-NEXT: orq %rsi, %rax284; X64-NEXT: retq285 %old = ptrtoint ptr %a to i64286 %old.not = and i64 %old, %m287 %offset = xor i64 %old.not, %m288 %p = getelementptr i8, ptr %a, i64 %offset289 ret ptr %p290}291 292define ptr @gep_and_xor_const(ptr %a) {293; X86-LABEL: gep_and_xor_const:294; X86: # %bb.0:295; X86-NEXT: movl {{[0-9]+}}(%esp), %eax296; X86-NEXT: orl $1, %eax297; X86-NEXT: retl298;299; X64-LABEL: gep_and_xor_const:300; X64: # %bb.0:301; X64-NEXT: movq %rdi, %rax302; X64-NEXT: orq $1, %rax303; X64-NEXT: retq304 %old = ptrtoint ptr %a to i64305 %old.not = and i64 %old, 1306 %offset = xor i64 %old.not, 1307 %p = getelementptr i8, ptr %a, i64 %offset308 ret ptr %p309}310 311define i64 @add_and_xor_const_zext_trunc(i64 %x) {312; X86-LABEL: add_and_xor_const_zext_trunc:313; X86: # %bb.0:314; X86-NEXT: movl {{[0-9]+}}(%esp), %eax315; X86-NEXT: movl {{[0-9]+}}(%esp), %edx316; X86-NEXT: orl $1, %eax317; X86-NEXT: retl318;319; X64-LABEL: add_and_xor_const_zext_trunc:320; X64: # %bb.0:321; X64-NEXT: movq %rdi, %rax322; X64-NEXT: orq $1, %rax323; X64-NEXT: retq324 %t = trunc i64 %x to i32325 %xor = xor i32 %t, -1326 %and = and i32 %xor, 1327 %ext = zext i32 %and to i64328 %add = add i64 %ext, %x329 ret i64 %add330}331 332define i64 @add_and_xor_const_zext_trunc_var(i64 %x, i64 %y) {333; X86-LABEL: add_and_xor_const_zext_trunc_var:334; X86: # %bb.0:335; X86-NEXT: movl {{[0-9]+}}(%esp), %edx336; X86-NEXT: movl {{[0-9]+}}(%esp), %eax337; X86-NEXT: orl {{[0-9]+}}(%esp), %eax338; X86-NEXT: retl339;340; X64-LABEL: add_and_xor_const_zext_trunc_var:341; X64: # %bb.0:342; X64-NEXT: movl %esi, %eax343; X64-NEXT: orq %rdi, %rax344; X64-NEXT: retq345 %tx = trunc i64 %x to i32346 %ty = trunc i64 %y to i32347 %xor = xor i32 %tx, -1348 %and = and i32 %ty, %xor349 %ext = zext i32 %and to i64350 %add = add i64 %ext, %x351 ret i64 %add352}353