Skip to content

Commit a5f22f2

Browse files
committed
[NFC][InstCombine] Tests for negation of 'or' with no common bits set
1 parent 102b410 commit a5f22f2

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

llvm/test/Transforms/InstCombine/sub-of-negatible.ll

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,3 +822,95 @@ neg_bb:
822822
nonneg_bb:
823823
ret i16 0
824824
}
825+
826+
; 'or' of 1 and operand with no lowest bit set is 'inc'
827+
define i8 @negation_of_increment_via_or_with_no_common_bits_set(i8 %x, i8 %y) {
828+
; CHECK-LABEL: @negation_of_increment_via_or_with_no_common_bits_set(
829+
; CHECK-NEXT: [[T0:%.*]] = shl i8 [[Y:%.*]], 1
830+
; CHECK-NEXT: [[T1:%.*]] = or i8 [[T0]], 1
831+
; CHECK-NEXT: [[T2:%.*]] = sub i8 [[X:%.*]], [[T1]]
832+
; CHECK-NEXT: ret i8 [[T2]]
833+
;
834+
%t0 = shl i8 %y, 1
835+
%t1 = or i8 %t0, 1
836+
%t2 = sub i8 %x, %t1
837+
ret i8 %t2
838+
}
839+
define i8 @negation_of_increment_via_or_with_no_common_bits_set_extrause(i8 %x, i8 %y) {
840+
; CHECK-LABEL: @negation_of_increment_via_or_with_no_common_bits_set_extrause(
841+
; CHECK-NEXT: [[T0:%.*]] = shl i8 [[Y:%.*]], 1
842+
; CHECK-NEXT: [[T1:%.*]] = or i8 [[T0]], 1
843+
; CHECK-NEXT: call void @use8(i8 [[T1]])
844+
; CHECK-NEXT: [[T2:%.*]] = sub i8 [[X:%.*]], [[T1]]
845+
; CHECK-NEXT: ret i8 [[T2]]
846+
;
847+
%t0 = shl i8 %y, 1
848+
%t1 = or i8 %t0, 1
849+
call void @use8(i8 %t1)
850+
%t2 = sub i8 %x, %t1
851+
ret i8 %t2
852+
}
853+
define i8 @negation_of_increment_via_or_common_bits_set(i8 %x, i8 %y) {
854+
; CHECK-LABEL: @negation_of_increment_via_or_common_bits_set(
855+
; CHECK-NEXT: [[T0:%.*]] = shl i8 [[Y:%.*]], 1
856+
; CHECK-NEXT: [[T1:%.*]] = or i8 [[T0]], 3
857+
; CHECK-NEXT: [[T2:%.*]] = sub i8 [[X:%.*]], [[T1]]
858+
; CHECK-NEXT: ret i8 [[T2]]
859+
;
860+
%t0 = shl i8 %y, 1
861+
%t1 = or i8 %t0, 3
862+
%t2 = sub i8 %x, %t1
863+
ret i8 %t2
864+
}
865+
866+
; 'or' of operands with no common bits set is 'add'
867+
define i8 @add_via_or_with_no_common_bits_set(i8 %x, i8 %y) {
868+
; CHECK-LABEL: @add_via_or_with_no_common_bits_set(
869+
; CHECK-NEXT: [[T0:%.*]] = sub i8 0, [[Y:%.*]]
870+
; CHECK-NEXT: call void @use8(i8 [[T0]])
871+
; CHECK-NEXT: [[T1:%.*]] = shl i8 [[T0]], 2
872+
; CHECK-NEXT: [[T2:%.*]] = or i8 [[T1]], 3
873+
; CHECK-NEXT: [[T3:%.*]] = sub i8 [[X:%.*]], [[T2]]
874+
; CHECK-NEXT: ret i8 [[T3]]
875+
;
876+
%t0 = sub i8 0, %y
877+
call void @use8(i8 %t0)
878+
%t1 = shl i8 %t0, 2
879+
%t2 = or i8 %t1, 3
880+
%t3 = sub i8 %x, %t2
881+
ret i8 %t3
882+
}
883+
define i8 @add_via_or_with_common_bit_maybe_set(i8 %x, i8 %y) {
884+
; CHECK-LABEL: @add_via_or_with_common_bit_maybe_set(
885+
; CHECK-NEXT: [[T0:%.*]] = sub i8 0, [[Y:%.*]]
886+
; CHECK-NEXT: call void @use8(i8 [[T0]])
887+
; CHECK-NEXT: [[T1:%.*]] = shl i8 [[T0]], 2
888+
; CHECK-NEXT: [[T2:%.*]] = or i8 [[T1]], 4
889+
; CHECK-NEXT: [[T3:%.*]] = sub i8 [[X:%.*]], [[T2]]
890+
; CHECK-NEXT: ret i8 [[T3]]
891+
;
892+
%t0 = sub i8 0, %y
893+
call void @use8(i8 %t0)
894+
%t1 = shl i8 %t0, 2
895+
%t2 = or i8 %t1, 4
896+
%t3 = sub i8 %x, %t2
897+
ret i8 %t3
898+
}
899+
define i8 @add_via_or_with_no_common_bits_set_extrause(i8 %x, i8 %y) {
900+
; CHECK-LABEL: @add_via_or_with_no_common_bits_set_extrause(
901+
; CHECK-NEXT: [[T0:%.*]] = sub i8 0, [[Y:%.*]]
902+
; CHECK-NEXT: call void @use8(i8 [[T0]])
903+
; CHECK-NEXT: [[T1:%.*]] = shl i8 [[T0]], 2
904+
; CHECK-NEXT: [[T2:%.*]] = or i8 [[T1]], 3
905+
; CHECK-NEXT: call void @use8(i8 [[T2]])
906+
; CHECK-NEXT: [[T3:%.*]] = sub i8 [[X:%.*]], [[T2]]
907+
; CHECK-NEXT: ret i8 [[T3]]
908+
;
909+
%t0 = sub i8 0, %y
910+
call void @use8(i8 %t0)
911+
%t1 = shl i8 %t0, 2
912+
%t2 = or i8 %t1, 3
913+
call void @use8(i8 %t2)
914+
%t3 = sub i8 %x, %t2
915+
ret i8 %t3
916+
}

0 commit comments

Comments
 (0)