Skip to content

Commit 77fb8cb

Browse files
committed
[InstCombine] update tests for logic folds to exercise commuted patterns; NFC
This was the intent for D88551. I also varied the types a bit for extra coverage and tried to make better test/value names.
1 parent 224fd6f commit 77fb8cb

File tree

1 file changed

+48
-54
lines changed
  • llvm/test/Transforms/InstCombine

1 file changed

+48
-54
lines changed

llvm/test/Transforms/InstCombine/xor.ll

Lines changed: 48 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,76 +1172,70 @@ define i8 @not_ashr_wrong_const(i8 %x) {
11721172
ret i8 %r
11731173
}
11741174

1175-
; (~A & B) ^ A --> (A | B)
1176-
; The division ops are here to thwart complexity-based canonicalization: all ops are binops.
1175+
; (~A & B) ^ A --> A | B
11771176

1178-
define i32 @test52(i32 %p1, i32 %p2) {
1179-
; CHECK-LABEL: @test52(
1180-
; CHECK-NEXT: [[A:%.*]] = udiv i32 42, [[P1:%.*]]
1181-
; CHECK-NEXT: [[B:%.*]] = udiv i32 42, [[P2:%.*]]
1182-
; CHECK-NEXT: [[O:%.*]] = xor i32 [[A]], -1
1183-
; CHECK-NEXT: [[R:%.*]] = and i32 [[B]], [[O]]
1184-
; CHECK-NEXT: [[Z:%.*]] = xor i32 [[R]], [[A]]
1185-
; CHECK-NEXT: ret i32 [[Z]]
1177+
define <2 x i32> @xor_andn_commute1(<2 x i32> %a, <2 x i32> %b) {
1178+
; CHECK-LABEL: @xor_andn_commute1(
1179+
; CHECK-NEXT: [[NOTA:%.*]] = xor <2 x i32> [[A:%.*]], <i32 -1, i32 -1>
1180+
; CHECK-NEXT: [[R:%.*]] = and <2 x i32> [[NOTA]], [[B:%.*]]
1181+
; CHECK-NEXT: [[Z:%.*]] = xor <2 x i32> [[R]], [[A]]
1182+
; CHECK-NEXT: ret <2 x i32> [[Z]]
11861183
;
1187-
%a = udiv i32 42, %p1
1188-
%b = udiv i32 42, %p2
1189-
%o = xor i32 %a, -1
1190-
%r = and i32 %o, %b
1191-
%z = xor i32 %r, %a
1192-
ret i32 %z
1184+
%nota = xor <2 x i32> %a, <i32 -1, i32 -1>
1185+
%r = and <2 x i32> %nota, %b
1186+
%z = xor <2 x i32> %r, %a
1187+
ret <2 x i32> %z
11931188
}
11941189

1195-
; (~B & A) ^ B --> (A | B)
1196-
; The division ops are here to thwart complexity-based canonicalization: all ops are binops.
1190+
; (B & ~A) ^ A --> A | B
11971191

1198-
define i32 @test53(i32 %p1, i32 %p2) {
1199-
; CHECK-LABEL: @test53(
1200-
; CHECK-NEXT: [[A:%.*]] = udiv i32 42, [[P1:%.*]]
1201-
; CHECK-NEXT: [[B:%.*]] = udiv i32 42, [[P2:%.*]]
1202-
; CHECK-NEXT: [[O:%.*]] = xor i32 [[B]], -1
1203-
; CHECK-NEXT: [[R:%.*]] = and i32 [[A]], [[O]]
1204-
; CHECK-NEXT: [[Z:%.*]] = xor i32 [[R]], [[B]]
1205-
; CHECK-NEXT: ret i32 [[Z]]
1192+
define i33 @xor_andn_commute2(i33 %a, i33 %pb) {
1193+
; CHECK-LABEL: @xor_andn_commute2(
1194+
; CHECK-NEXT: [[B:%.*]] = udiv i33 42, [[PB:%.*]]
1195+
; CHECK-NEXT: [[NOTA:%.*]] = xor i33 [[A:%.*]], -1
1196+
; CHECK-NEXT: [[R:%.*]] = and i33 [[B]], [[NOTA]]
1197+
; CHECK-NEXT: [[Z:%.*]] = xor i33 [[R]], [[A]]
1198+
; CHECK-NEXT: ret i33 [[Z]]
12061199
;
1207-
%a = udiv i32 42, %p1
1208-
%b = udiv i32 42, %p2
1209-
%o = xor i32 %b, -1
1210-
%r = and i32 %o, %a
1211-
%z = xor i32 %r, %b
1212-
ret i32 %z
1200+
%b = udiv i33 42, %pb ; thwart complexity-based canonicalization
1201+
%nota = xor i33 %a, -1
1202+
%r = and i33 %b, %nota
1203+
%z = xor i33 %r, %a
1204+
ret i33 %z
12131205
}
12141206

1215-
define i32 @test54(i32 %p1, i32 %p2) {
1216-
; CHECK-LABEL: @test54(
1217-
; CHECK-NEXT: [[A:%.*]] = udiv i32 42, [[P1:%.*]]
1218-
; CHECK-NEXT: [[B:%.*]] = udiv i32 42, [[P2:%.*]]
1219-
; CHECK-NEXT: [[O:%.*]] = xor i32 [[A]], -1
1220-
; CHECK-NEXT: [[R:%.*]] = and i32 [[B]], [[O]]
1221-
; CHECK-NEXT: [[Z:%.*]] = xor i32 [[R]], [[A]]
1207+
; A ^ (~A & B) --> A | B
1208+
1209+
define i32 @xor_andn_commute3(i32 %pa, i32 %b) {
1210+
; CHECK-LABEL: @xor_andn_commute3(
1211+
; CHECK-NEXT: [[A:%.*]] = udiv i32 42, [[PA:%.*]]
1212+
; CHECK-NEXT: [[NOTA:%.*]] = xor i32 [[A]], -1
1213+
; CHECK-NEXT: [[R:%.*]] = and i32 [[NOTA]], [[B:%.*]]
1214+
; CHECK-NEXT: [[Z:%.*]] = xor i32 [[A]], [[R]]
12221215
; CHECK-NEXT: ret i32 [[Z]]
12231216
;
1224-
%a = udiv i32 42, %p1
1225-
%b = udiv i32 42, %p2
1226-
%o = xor i32 %a, -1
1227-
%r = and i32 %b, %o
1228-
%z = xor i32 %r, %a
1217+
%a = udiv i32 42, %pa ; thwart complexity-based canonicalization
1218+
%nota = xor i32 %a, -1
1219+
%r = and i32 %nota, %b
1220+
%z = xor i32 %a, %r
12291221
ret i32 %z
12301222
}
12311223

1232-
define i32 @test55(i32 %p1, i32 %p2) {
1233-
; CHECK-LABEL: @test55(
1234-
; CHECK-NEXT: [[A:%.*]] = udiv i32 42, [[P1:%.*]]
1235-
; CHECK-NEXT: [[B:%.*]] = udiv i32 42, [[P2:%.*]]
1236-
; CHECK-NEXT: [[O:%.*]] = xor i32 [[A]], -1
1237-
; CHECK-NEXT: [[R:%.*]] = and i32 [[B]], [[O]]
1224+
; A ^ (B & ~A) --> A | B
1225+
1226+
define i32 @xor_andn_commute4(i32 %pa, i32 %pb) {
1227+
; CHECK-LABEL: @xor_andn_commute4(
1228+
; CHECK-NEXT: [[A:%.*]] = udiv i32 42, [[PA:%.*]]
1229+
; CHECK-NEXT: [[B:%.*]] = udiv i32 42, [[PB:%.*]]
1230+
; CHECK-NEXT: [[NOTA:%.*]] = xor i32 [[A]], -1
1231+
; CHECK-NEXT: [[R:%.*]] = and i32 [[B]], [[NOTA]]
12381232
; CHECK-NEXT: [[Z:%.*]] = xor i32 [[A]], [[R]]
12391233
; CHECK-NEXT: ret i32 [[Z]]
12401234
;
1241-
%a = udiv i32 42, %p1
1242-
%b = udiv i32 42, %p2
1243-
%o = xor i32 %a, -1
1244-
%r = and i32 %o, %b
1235+
%a = udiv i32 42, %pa ; thwart complexity-based canonicalization
1236+
%b = udiv i32 42, %pb ; thwart complexity-based canonicalization
1237+
%nota = xor i32 %a, -1
1238+
%r = and i32 %b, %nota
12451239
%z = xor i32 %a, %r
12461240
ret i32 %z
12471241
}

0 commit comments

Comments
 (0)