Skip to content

Commit d40c111

Browse files
committed
[AArch64] Add Tests for Reassociation of SUBS with Non-Constant; NFC
1 parent 8e85b77 commit d40c111

File tree

1 file changed

+348
-16
lines changed

1 file changed

+348
-16
lines changed

llvm/test/CodeGen/AArch64/csel-cmp-cse.ll

Lines changed: 348 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,306 @@ define i32 @test_eq0_multi_use_sub_i32(i32 %x0, i32 %x1) {
335335
ret i32 %ret
336336
}
337337

338+
define i32 @test_eq_nonconst_sub_add_i32(i32 %x0, i32 %x1, i32 %x2) {
339+
; CHECK-LABEL: test_eq_nonconst_sub_add_i32:
340+
; CHECK: // %bb.0:
341+
; CHECK-NEXT: add w8, w0, w1
342+
; CHECK-NEXT: cmp w1, w2
343+
; CHECK-NEXT: sub w8, w8, w2
344+
; CHECK-NEXT: csel w0, wzr, w8, eq
345+
; CHECK-NEXT: ret
346+
%cmp = icmp eq i32 %x1, %x2
347+
%add = add nuw i32 %x0, %x1
348+
%sub = sub i32 %add, %x2
349+
%ret = select i1 %cmp, i32 0, i32 %sub
350+
ret i32 %ret
351+
}
352+
353+
define i32 @test_ne_nonconst_sub_add_i32(i32 %x0, i32 %x1, i32 %x2) {
354+
; CHECK-LABEL: test_ne_nonconst_sub_add_i32:
355+
; CHECK: // %bb.0:
356+
; CHECK-NEXT: add w8, w0, w1
357+
; CHECK-NEXT: cmp w1, w2
358+
; CHECK-NEXT: sub w8, w8, w2
359+
; CHECK-NEXT: csel w0, wzr, w8, ne
360+
; CHECK-NEXT: ret
361+
%cmp = icmp ne i32 %x1, %x2
362+
%add = add nuw i32 %x0, %x1
363+
%sub = sub i32 %add, %x2
364+
%ret = select i1 %cmp, i32 0, i32 %sub
365+
ret i32 %ret
366+
}
367+
368+
define i32 @test_ult_nonconst_i32(i32 %x0, i32 %x1, i32 %x2) {
369+
; CHECK-LABEL: test_ult_nonconst_i32:
370+
; CHECK: // %bb.0:
371+
; CHECK-NEXT: add w8, w0, w1
372+
; CHECK-NEXT: cmp w1, w2
373+
; CHECK-NEXT: sub w8, w8, w2
374+
; CHECK-NEXT: csel w0, wzr, w8, lo
375+
; CHECK-NEXT: ret
376+
%cmp = icmp ult i32 %x1, %x2
377+
%add = add i32 %x0, %x1
378+
%sub = sub i32 %add, %x2
379+
%ret = select i1 %cmp, i32 0, i32 %sub
380+
ret i32 %ret
381+
}
382+
383+
define i32 @test_ule_nonconst_i32(i32 %x0, i32 %x1, i32 %x2) {
384+
; CHECK-LABEL: test_ule_nonconst_i32:
385+
; CHECK: // %bb.0:
386+
; CHECK-NEXT: add w8, w0, w1
387+
; CHECK-NEXT: cmp w1, w2
388+
; CHECK-NEXT: sub w8, w8, w2
389+
; CHECK-NEXT: csel w0, wzr, w8, ls
390+
; CHECK-NEXT: ret
391+
%cmp = icmp ule i32 %x1, %x2
392+
%add = add i32 %x0, %x1
393+
%sub = sub i32 %add, %x2
394+
%ret = select i1 %cmp, i32 0, i32 %sub
395+
ret i32 %ret
396+
}
397+
398+
define i32 @test_ugt_nonconst_i32(i32 %x0, i32 %x1, i32 %x2) {
399+
; CHECK-LABEL: test_ugt_nonconst_i32:
400+
; CHECK: // %bb.0:
401+
; CHECK-NEXT: add w8, w0, w1
402+
; CHECK-NEXT: cmp w1, w2
403+
; CHECK-NEXT: sub w8, w8, w2
404+
; CHECK-NEXT: csel w0, wzr, w8, hi
405+
; CHECK-NEXT: ret
406+
%cmp = icmp ugt i32 %x1, %x2
407+
%add = add i32 %x0, %x1
408+
%sub = sub i32 %add, %x2
409+
%ret = select i1 %cmp, i32 0, i32 %sub
410+
ret i32 %ret
411+
}
412+
413+
define i32 @test_uge_nonconst_i32(i32 %x0, i32 %x1, i32 %x2) {
414+
; CHECK-LABEL: test_uge_nonconst_i32:
415+
; CHECK: // %bb.0:
416+
; CHECK-NEXT: add w8, w0, w1
417+
; CHECK-NEXT: cmp w1, w2
418+
; CHECK-NEXT: sub w8, w8, w2
419+
; CHECK-NEXT: csel w0, wzr, w8, hs
420+
; CHECK-NEXT: ret
421+
%cmp = icmp uge i32 %x1, %x2
422+
%add = add i32 %x0, %x1
423+
%sub = sub i32 %add, %x2
424+
%ret = select i1 %cmp, i32 0, i32 %sub
425+
ret i32 %ret
426+
}
427+
428+
define i32 @test_slt_nonconst_i32(i32 %x0, i32 %x1, i32 %x2) {
429+
; CHECK-LABEL: test_slt_nonconst_i32:
430+
; CHECK: // %bb.0:
431+
; CHECK-NEXT: add w8, w0, w1
432+
; CHECK-NEXT: cmp w1, w2
433+
; CHECK-NEXT: sub w8, w8, w2
434+
; CHECK-NEXT: csel w0, wzr, w8, lt
435+
; CHECK-NEXT: ret
436+
%cmp = icmp slt i32 %x1, %x2
437+
%add = add i32 %x0, %x1
438+
%sub = sub i32 %add, %x2
439+
%ret = select i1 %cmp, i32 0, i32 %sub
440+
ret i32 %ret
441+
}
442+
443+
define i32 @test_sle_nonconst_i32(i32 %x0, i32 %x1, i32 %x2) {
444+
; CHECK-LABEL: test_sle_nonconst_i32:
445+
; CHECK: // %bb.0:
446+
; CHECK-NEXT: add w8, w0, w1
447+
; CHECK-NEXT: cmp w1, w2
448+
; CHECK-NEXT: sub w8, w8, w2
449+
; CHECK-NEXT: csel w0, wzr, w8, le
450+
; CHECK-NEXT: ret
451+
%cmp = icmp sle i32 %x1, %x2
452+
%add = add i32 %x0, %x1
453+
%sub = sub i32 %add, %x2
454+
%ret = select i1 %cmp, i32 0, i32 %sub
455+
ret i32 %ret
456+
}
457+
458+
define i32 @test_sgt_nonconst_i32(i32 %x0, i32 %x1, i32 %x2) {
459+
; CHECK-LABEL: test_sgt_nonconst_i32:
460+
; CHECK: // %bb.0:
461+
; CHECK-NEXT: add w8, w0, w1
462+
; CHECK-NEXT: cmp w1, w2
463+
; CHECK-NEXT: sub w8, w8, w2
464+
; CHECK-NEXT: csel w0, wzr, w8, gt
465+
; CHECK-NEXT: ret
466+
%cmp = icmp sgt i32 %x1, %x2
467+
%add = add i32 %x0, %x1
468+
%sub = sub i32 %add, %x2
469+
%ret = select i1 %cmp, i32 0, i32 %sub
470+
ret i32 %ret
471+
}
472+
473+
define i32 @test_sge_nonconst_i32(i32 %x0, i32 %x1, i32 %x2) {
474+
; CHECK-LABEL: test_sge_nonconst_i32:
475+
; CHECK: // %bb.0:
476+
; CHECK-NEXT: add w8, w0, w1
477+
; CHECK-NEXT: cmp w1, w2
478+
; CHECK-NEXT: sub w8, w8, w2
479+
; CHECK-NEXT: csel w0, wzr, w8, ge
480+
; CHECK-NEXT: ret
481+
%cmp = icmp sge i32 %x1, %x2
482+
%add = add i32 %x0, %x1
483+
%sub = sub i32 %add, %x2
484+
%ret = select i1 %cmp, i32 0, i32 %sub
485+
ret i32 %ret
486+
}
487+
488+
define i32 @test_eq_nonconst_sub_add_comm_i32(i32 %x0, i32 %x1, i32 %x2) {
489+
; CHECK-LABEL: test_eq_nonconst_sub_add_comm_i32:
490+
; CHECK: // %bb.0:
491+
; CHECK-NEXT: add w8, w0, w1
492+
; CHECK-NEXT: cmp w2, w1
493+
; CHECK-NEXT: sub w8, w8, w2
494+
; CHECK-NEXT: csel w0, wzr, w8, eq
495+
; CHECK-NEXT: ret
496+
%cmp = icmp eq i32 %x2, %x1
497+
%add = add nuw i32 %x0, %x1
498+
%sub = sub i32 %add, %x2
499+
%ret = select i1 %cmp, i32 0, i32 %sub
500+
ret i32 %ret
501+
}
502+
503+
define i32 @test_ne_nonconst_sub_add_comm_i32(i32 %x0, i32 %x1, i32 %x2) {
504+
; CHECK-LABEL: test_ne_nonconst_sub_add_comm_i32:
505+
; CHECK: // %bb.0:
506+
; CHECK-NEXT: add w8, w0, w1
507+
; CHECK-NEXT: cmp w2, w1
508+
; CHECK-NEXT: sub w8, w8, w2
509+
; CHECK-NEXT: csel w0, wzr, w8, ne
510+
; CHECK-NEXT: ret
511+
%cmp = icmp ne i32 %x2, %x1
512+
%add = add nuw i32 %x0, %x1
513+
%sub = sub i32 %add, %x2
514+
%ret = select i1 %cmp, i32 0, i32 %sub
515+
ret i32 %ret
516+
}
517+
518+
define i32 @test_ult_nonconst_sub_add_comm_i32(i32 %x0, i32 %x1, i32 %x2) {
519+
; CHECK-LABEL: test_ult_nonconst_sub_add_comm_i32:
520+
; CHECK: // %bb.0:
521+
; CHECK-NEXT: add w8, w0, w1
522+
; CHECK-NEXT: cmp w2, w1
523+
; CHECK-NEXT: sub w8, w8, w2
524+
; CHECK-NEXT: csel w0, wzr, w8, lo
525+
; CHECK-NEXT: ret
526+
%cmp = icmp ult i32 %x2, %x1
527+
%add = add nuw i32 %x0, %x1
528+
%sub = sub i32 %add, %x2
529+
%ret = select i1 %cmp, i32 0, i32 %sub
530+
ret i32 %ret
531+
}
532+
533+
define i32 @test_ule_nonconst_sub_add_comm_i32(i32 %x0, i32 %x1, i32 %x2) {
534+
; CHECK-LABEL: test_ule_nonconst_sub_add_comm_i32:
535+
; CHECK: // %bb.0:
536+
; CHECK-NEXT: add w8, w0, w1
537+
; CHECK-NEXT: cmp w2, w1
538+
; CHECK-NEXT: sub w8, w8, w2
539+
; CHECK-NEXT: csel w0, wzr, w8, ls
540+
; CHECK-NEXT: ret
541+
%cmp = icmp ule i32 %x2, %x1
542+
%add = add nuw i32 %x0, %x1
543+
%sub = sub i32 %add, %x2
544+
%ret = select i1 %cmp, i32 0, i32 %sub
545+
ret i32 %ret
546+
}
547+
548+
define i32 @test_ugt_nonconst_sub_add_comm_i32(i32 %x0, i32 %x1, i32 %x2) {
549+
; CHECK-LABEL: test_ugt_nonconst_sub_add_comm_i32:
550+
; CHECK: // %bb.0:
551+
; CHECK-NEXT: add w8, w0, w1
552+
; CHECK-NEXT: cmp w2, w1
553+
; CHECK-NEXT: sub w8, w8, w2
554+
; CHECK-NEXT: csel w0, wzr, w8, hi
555+
; CHECK-NEXT: ret
556+
%cmp = icmp ugt i32 %x2, %x1
557+
%add = add nuw i32 %x0, %x1
558+
%sub = sub i32 %add, %x2
559+
%ret = select i1 %cmp, i32 0, i32 %sub
560+
ret i32 %ret
561+
}
562+
563+
define i32 @test_uge_nonconst_sub_add_comm_i32(i32 %x0, i32 %x1, i32 %x2) {
564+
; CHECK-LABEL: test_uge_nonconst_sub_add_comm_i32:
565+
; CHECK: // %bb.0:
566+
; CHECK-NEXT: add w8, w0, w1
567+
; CHECK-NEXT: cmp w2, w1
568+
; CHECK-NEXT: sub w8, w8, w2
569+
; CHECK-NEXT: csel w0, wzr, w8, hs
570+
; CHECK-NEXT: ret
571+
%cmp = icmp uge i32 %x2, %x1
572+
%add = add nuw i32 %x0, %x1
573+
%sub = sub i32 %add, %x2
574+
%ret = select i1 %cmp, i32 0, i32 %sub
575+
ret i32 %ret
576+
}
577+
578+
define i32 @test_slt_nonconst_sub_add_comm_i32(i32 %x0, i32 %x1, i32 %x2) {
579+
; CHECK-LABEL: test_slt_nonconst_sub_add_comm_i32:
580+
; CHECK: // %bb.0:
581+
; CHECK-NEXT: add w8, w0, w1
582+
; CHECK-NEXT: cmp w2, w1
583+
; CHECK-NEXT: sub w8, w8, w2
584+
; CHECK-NEXT: csel w0, wzr, w8, lt
585+
; CHECK-NEXT: ret
586+
%cmp = icmp slt i32 %x2, %x1
587+
%add = add nuw i32 %x0, %x1
588+
%sub = sub i32 %add, %x2
589+
%ret = select i1 %cmp, i32 0, i32 %sub
590+
ret i32 %ret
591+
}
592+
593+
define i32 @test_sle_nonconst_sub_add_comm_i32(i32 %x0, i32 %x1, i32 %x2) {
594+
; CHECK-LABEL: test_sle_nonconst_sub_add_comm_i32:
595+
; CHECK: // %bb.0:
596+
; CHECK-NEXT: add w8, w0, w1
597+
; CHECK-NEXT: cmp w2, w1
598+
; CHECK-NEXT: sub w8, w8, w2
599+
; CHECK-NEXT: csel w0, wzr, w8, le
600+
; CHECK-NEXT: ret
601+
%cmp = icmp sle i32 %x2, %x1
602+
%add = add nuw i32 %x0, %x1
603+
%sub = sub i32 %add, %x2
604+
%ret = select i1 %cmp, i32 0, i32 %sub
605+
ret i32 %ret
606+
}
607+
608+
define i32 @test_sgt_nonconst_sub_add_comm_i32(i32 %x0, i32 %x1, i32 %x2) {
609+
; CHECK-LABEL: test_sgt_nonconst_sub_add_comm_i32:
610+
; CHECK: // %bb.0:
611+
; CHECK-NEXT: add w8, w0, w1
612+
; CHECK-NEXT: cmp w2, w1
613+
; CHECK-NEXT: sub w8, w8, w2
614+
; CHECK-NEXT: csel w0, wzr, w8, gt
615+
; CHECK-NEXT: ret
616+
%cmp = icmp sgt i32 %x2, %x1
617+
%add = add nuw i32 %x0, %x1
618+
%sub = sub i32 %add, %x2
619+
%ret = select i1 %cmp, i32 0, i32 %sub
620+
ret i32 %ret
621+
}
622+
623+
define i32 @test_sge_nonconst_sub_add_comm_i32(i32 %x0, i32 %x1, i32 %x2) {
624+
; CHECK-LABEL: test_sge_nonconst_sub_add_comm_i32:
625+
; CHECK: // %bb.0:
626+
; CHECK-NEXT: add w8, w0, w1
627+
; CHECK-NEXT: cmp w2, w1
628+
; CHECK-NEXT: sub w8, w8, w2
629+
; CHECK-NEXT: csel w0, wzr, w8, ge
630+
; CHECK-NEXT: ret
631+
%cmp = icmp sge i32 %x2, %x1
632+
%add = add nuw i32 %x0, %x1
633+
%sub = sub i32 %add, %x2
634+
%ret = select i1 %cmp, i32 0, i32 %sub
635+
ret i32 %ret
636+
}
637+
338638
; Negative test
339639
define i32 @test_eq0_multi_use_cmp_i32(i32 %x0, i32 %x1) {
340640
; CHECK-LABEL: test_eq0_multi_use_cmp_i32:
@@ -421,22 +721,6 @@ define i32 @test_ugtsmax_sub_add_i32(i32 %x0, i32 %x1) {
421721
ret i32 %ret
422722
}
423723

424-
; Negative test
425-
define i32 @test_ult_nonconst_i32(i32 %x0, i32 %x1, i32 %x2) {
426-
; CHECK-LABEL: test_ult_nonconst_i32:
427-
; CHECK: // %bb.0:
428-
; CHECK-NEXT: add w8, w0, w1
429-
; CHECK-NEXT: cmp w1, w2
430-
; CHECK-NEXT: sub w8, w8, w2
431-
; CHECK-NEXT: csel w0, wzr, w8, lo
432-
; CHECK-NEXT: ret
433-
%cmp = icmp ult i32 %x1, %x2
434-
%add = add i32 %x0, %x1
435-
%sub = sub i32 %add, %x2
436-
%ret = select i1 %cmp, i32 0, i32 %sub
437-
ret i32 %ret
438-
}
439-
440724
; Negative test
441725
define i32 @test_eq_const_mismatch_i32(i32 %x0, i32 %x1) {
442726
; CHECK-LABEL: test_eq_const_mismatch_i32:
@@ -771,3 +1055,51 @@ define i32 @test_eq0_bitwidth_mismatch_2(i32 %x0, i64 %x1) {
7711055
%ret = select i1 %cmp, i32 0, i32 %sub
7721056
ret i32 %ret
7731057
}
1058+
1059+
; Negative test
1060+
define i32 @test_ult_nonconst_op_mismatch_i32(i32 %x0, i32 %x1, i32 %x2) {
1061+
; CHECK-LABEL: test_ult_nonconst_op_mismatch_i32:
1062+
; CHECK: // %bb.0:
1063+
; CHECK-NEXT: add w8, w0, w1
1064+
; CHECK-NEXT: cmp w1, w2
1065+
; CHECK-NEXT: add w8, w8, w2
1066+
; CHECK-NEXT: csel w0, wzr, w8, lo
1067+
; CHECK-NEXT: ret
1068+
%cmp = icmp ult i32 %x1, %x2
1069+
%add = add i32 %x0, %x1
1070+
%sub = add i32 %add, %x2
1071+
%ret = select i1 %cmp, i32 0, i32 %sub
1072+
ret i32 %ret
1073+
}
1074+
1075+
; Negative test
1076+
define i32 @test_ult_nonconst_unrelated_i32(i32 %x0, i32 %x1, i32 %x2, i32 %x3) {
1077+
; CHECK-LABEL: test_ult_nonconst_unrelated_i32:
1078+
; CHECK: // %bb.0:
1079+
; CHECK-NEXT: add w8, w0, w1
1080+
; CHECK-NEXT: cmp w1, w2
1081+
; CHECK-NEXT: sub w8, w8, w3
1082+
; CHECK-NEXT: csel w0, wzr, w8, lo
1083+
; CHECK-NEXT: ret
1084+
%cmp = icmp ult i32 %x1, %x2
1085+
%add = add i32 %x0, %x1
1086+
%sub = sub i32 %add, %x3
1087+
%ret = select i1 %cmp, i32 0, i32 %sub
1088+
ret i32 %ret
1089+
}
1090+
1091+
; Negative test
1092+
define i32 @test_ult_nonconst_unrelated_2_i32(i32 %x0, i32 %x1, i32 %x2, i32 %x3) {
1093+
; CHECK-LABEL: test_ult_nonconst_unrelated_2_i32:
1094+
; CHECK: // %bb.0:
1095+
; CHECK-NEXT: add w8, w0, w1
1096+
; CHECK-NEXT: cmp w2, w1
1097+
; CHECK-NEXT: sub w8, w8, w3
1098+
; CHECK-NEXT: csel w0, wzr, w8, lo
1099+
; CHECK-NEXT: ret
1100+
%cmp = icmp ult i32 %x2, %x1
1101+
%add = add i32 %x0, %x1
1102+
%sub = sub i32 %add, %x3
1103+
%ret = select i1 %cmp, i32 0, i32 %sub
1104+
ret i32 %ret
1105+
}

0 commit comments

Comments
 (0)