ret i8 %m
}
+define i8 @freeToInvert(i8 %x, i8 %y, i8 %z) {
+; CHECK-LABEL: @freeToInvert(
+; CHECK-NEXT: [[NX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT: [[NY:%.*]] = xor i8 [[Y:%.*]], -1
+; CHECK-NEXT: [[NZ:%.*]] = xor i8 [[Z:%.*]], -1
+; CHECK-NEXT: call void @use(i8 [[NX]])
+; CHECK-NEXT: call void @use(i8 [[NY]])
+; CHECK-NEXT: call void @use(i8 [[NZ]])
+; CHECK-NEXT: [[TMP1:%.*]] = call i8 @llvm.umin.i8(i8 [[X]], i8 [[Y]])
+; CHECK-NEXT: [[TMP2:%.*]] = call i8 @llvm.smax.i8(i8 [[Z]], i8 [[TMP1]])
+; CHECK-NEXT: ret i8 [[TMP2]]
+;
+ %nx = xor i8 %x, -1
+ %ny = xor i8 %y, -1
+ %nz = xor i8 %z, -1
+ call void @use(i8 %nx)
+ call void @use(i8 %ny)
+ call void @use(i8 %nz)
+ %m1 = call i8 @llvm.umax.i8(i8 %nx, i8 %ny)
+ %m2 = call i8 @llvm.smin.i8(i8 %m1, i8 %nz)
+ %not = xor i8 %m2, -1
+ ret i8 %not
+}
+
+define i8 @freeToInvert_use1(i8 %x, i8 %y, i8 %z) {
+; CHECK-LABEL: @freeToInvert_use1(
+; CHECK-NEXT: [[NX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT: [[NY:%.*]] = xor i8 [[Y:%.*]], -1
+; CHECK-NEXT: [[NZ:%.*]] = xor i8 [[Z:%.*]], -1
+; CHECK-NEXT: call void @use(i8 [[NX]])
+; CHECK-NEXT: call void @use(i8 [[NY]])
+; CHECK-NEXT: call void @use(i8 [[NZ]])
+; CHECK-NEXT: [[M1:%.*]] = call i8 @llvm.umax.i8(i8 [[NX]], i8 [[NY]])
+; CHECK-NEXT: call void @use(i8 [[M1]])
+; CHECK-NEXT: [[TMP1:%.*]] = xor i8 [[M1]], -1
+; CHECK-NEXT: [[TMP2:%.*]] = call i8 @llvm.smax.i8(i8 [[Z]], i8 [[TMP1]])
+; CHECK-NEXT: ret i8 [[TMP2]]
+;
+ %nx = xor i8 %x, -1
+ %ny = xor i8 %y, -1
+ %nz = xor i8 %z, -1
+ call void @use(i8 %nx)
+ call void @use(i8 %ny)
+ call void @use(i8 %nz)
+ %m1 = call i8 @llvm.umax.i8(i8 %nx, i8 %ny)
+ call void @use(i8 %m1)
+ %m2 = call i8 @llvm.smin.i8(i8 %m1, i8 %nz)
+ %not = xor i8 %m2, -1
+ ret i8 %not
+}
+
+define i8 @freeToInvert_use2(i8 %x, i8 %y, i8 %z) {
+; CHECK-LABEL: @freeToInvert_use2(
+; CHECK-NEXT: [[NX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT: [[NY:%.*]] = xor i8 [[Y:%.*]], -1
+; CHECK-NEXT: [[NZ:%.*]] = xor i8 [[Z:%.*]], -1
+; CHECK-NEXT: call void @use(i8 [[NX]])
+; CHECK-NEXT: call void @use(i8 [[NY]])
+; CHECK-NEXT: call void @use(i8 [[NZ]])
+; CHECK-NEXT: [[M1:%.*]] = call i8 @llvm.umax.i8(i8 [[NX]], i8 [[NY]])
+; CHECK-NEXT: [[M2:%.*]] = call i8 @llvm.smin.i8(i8 [[M1]], i8 [[NZ]])
+; CHECK-NEXT: call void @use(i8 [[M2]])
+; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[M2]], -1
+; CHECK-NEXT: ret i8 [[NOT]]
+;
+ %nx = xor i8 %x, -1
+ %ny = xor i8 %y, -1
+ %nz = xor i8 %z, -1
+ call void @use(i8 %nx)
+ call void @use(i8 %ny)
+ call void @use(i8 %nz)
+ %m1 = call i8 @llvm.umax.i8(i8 %nx, i8 %ny)
+ %m2 = call i8 @llvm.smin.i8(i8 %m1, i8 %nz)
+ call void @use(i8 %m2)
+ %not = xor i8 %m2, -1
+ ret i8 %not
+}
+
+define i8 @freeToInvert_use3(i8 %x, i8 %y, i8 %z) {
+; CHECK-LABEL: @freeToInvert_use3(
+; CHECK-NEXT: [[NX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT: [[NY:%.*]] = xor i8 [[Y:%.*]], -1
+; CHECK-NEXT: [[NZ:%.*]] = xor i8 [[Z:%.*]], -1
+; CHECK-NEXT: call void @use(i8 [[NX]])
+; CHECK-NEXT: call void @use(i8 [[NY]])
+; CHECK-NEXT: call void @use(i8 [[NZ]])
+; CHECK-NEXT: [[M1:%.*]] = call i8 @llvm.umax.i8(i8 [[NX]], i8 [[NY]])
+; CHECK-NEXT: call void @use(i8 [[M1]])
+; CHECK-NEXT: [[M2:%.*]] = call i8 @llvm.smin.i8(i8 [[M1]], i8 [[NZ]])
+; CHECK-NEXT: call void @use(i8 [[M2]])
+; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[M2]], -1
+; CHECK-NEXT: ret i8 [[NOT]]
+;
+ %nx = xor i8 %x, -1
+ %ny = xor i8 %y, -1
+ %nz = xor i8 %z, -1
+ call void @use(i8 %nx)
+ call void @use(i8 %ny)
+ call void @use(i8 %nz)
+ %m1 = call i8 @llvm.umax.i8(i8 %nx, i8 %ny)
+ call void @use(i8 %m1)
+ %m2 = call i8 @llvm.smin.i8(i8 %m1, i8 %nz)
+ call void @use(i8 %m2)
+ %not = xor i8 %m2, -1
+ ret i8 %not
+}
+
+define i8 @freeToInvert_two_minmax_ops(i8 %x, i8 %y, i8 %z, i8 %w) {
+; CHECK-LABEL: @freeToInvert_two_minmax_ops(
+; CHECK-NEXT: [[NX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT: [[NY:%.*]] = xor i8 [[Y:%.*]], -1
+; CHECK-NEXT: [[NZ:%.*]] = xor i8 [[Z:%.*]], -1
+; CHECK-NEXT: [[NW:%.*]] = xor i8 [[W:%.*]], -1
+; CHECK-NEXT: call void @use(i8 [[NX]])
+; CHECK-NEXT: call void @use(i8 [[NY]])
+; CHECK-NEXT: call void @use(i8 [[NZ]])
+; CHECK-NEXT: call void @use(i8 [[NW]])
+; CHECK-NEXT: [[M1:%.*]] = call i8 @llvm.umax.i8(i8 [[NX]], i8 [[NY]])
+; CHECK-NEXT: [[M2:%.*]] = call i8 @llvm.smax.i8(i8 [[NW]], i8 [[NZ]])
+; CHECK-NEXT: [[M3:%.*]] = call i8 @llvm.smin.i8(i8 [[M1]], i8 [[M2]])
+; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[M3]], -1
+; CHECK-NEXT: ret i8 [[NOT]]
+;
+ %nx = xor i8 %x, -1
+ %ny = xor i8 %y, -1
+ %nz = xor i8 %z, -1
+ %nw = xor i8 %w, -1
+ call void @use(i8 %nx)
+ call void @use(i8 %ny)
+ call void @use(i8 %nz)
+ call void @use(i8 %nw)
+ %m1 = call i8 @llvm.umax.i8(i8 %nx, i8 %ny)
+ %m2 = call i8 @llvm.smax.i8(i8 %nw, i8 %nz)
+ %m3 = call i8 @llvm.smin.i8(i8 %m1, i8 %m2)
+ %not = xor i8 %m3, -1
+ ret i8 %not
+}
+
+define i8 @freeToInvert_two_minmax_ops_use1(i8 %x, i8 %y, i8 %z, i8 %w) {
+; CHECK-LABEL: @freeToInvert_two_minmax_ops_use1(
+; CHECK-NEXT: [[NX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT: [[NY:%.*]] = xor i8 [[Y:%.*]], -1
+; CHECK-NEXT: [[NZ:%.*]] = xor i8 [[Z:%.*]], -1
+; CHECK-NEXT: [[NW:%.*]] = xor i8 [[W:%.*]], -1
+; CHECK-NEXT: call void @use(i8 [[NX]])
+; CHECK-NEXT: call void @use(i8 [[NY]])
+; CHECK-NEXT: call void @use(i8 [[NZ]])
+; CHECK-NEXT: call void @use(i8 [[NW]])
+; CHECK-NEXT: [[M1:%.*]] = call i8 @llvm.umax.i8(i8 [[NX]], i8 [[NY]])
+; CHECK-NEXT: call void @use(i8 [[M1]])
+; CHECK-NEXT: [[M2:%.*]] = call i8 @llvm.smax.i8(i8 [[NW]], i8 [[NZ]])
+; CHECK-NEXT: [[M3:%.*]] = call i8 @llvm.smin.i8(i8 [[M1]], i8 [[M2]])
+; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[M3]], -1
+; CHECK-NEXT: ret i8 [[NOT]]
+;
+ %nx = xor i8 %x, -1
+ %ny = xor i8 %y, -1
+ %nz = xor i8 %z, -1
+ %nw = xor i8 %w, -1
+ call void @use(i8 %nx)
+ call void @use(i8 %ny)
+ call void @use(i8 %nz)
+ call void @use(i8 %nw)
+ %m1 = call i8 @llvm.umax.i8(i8 %nx, i8 %ny)
+ call void @use(i8 %m1)
+ %m2 = call i8 @llvm.smax.i8(i8 %nw, i8 %nz)
+ %m3 = call i8 @llvm.smin.i8(i8 %m1, i8 %m2)
+ %not = xor i8 %m3, -1
+ ret i8 %not
+}
+
+define i8 @freeToInvert_two_minmax_ops_use2(i8 %x, i8 %y, i8 %z, i8 %w) {
+; CHECK-LABEL: @freeToInvert_two_minmax_ops_use2(
+; CHECK-NEXT: [[NX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT: [[NY:%.*]] = xor i8 [[Y:%.*]], -1
+; CHECK-NEXT: [[NZ:%.*]] = xor i8 [[Z:%.*]], -1
+; CHECK-NEXT: [[NW:%.*]] = xor i8 [[W:%.*]], -1
+; CHECK-NEXT: call void @use(i8 [[NX]])
+; CHECK-NEXT: call void @use(i8 [[NY]])
+; CHECK-NEXT: call void @use(i8 [[NZ]])
+; CHECK-NEXT: call void @use(i8 [[NW]])
+; CHECK-NEXT: [[M1:%.*]] = call i8 @llvm.umax.i8(i8 [[NX]], i8 [[NY]])
+; CHECK-NEXT: [[M2:%.*]] = call i8 @llvm.smax.i8(i8 [[NW]], i8 [[NZ]])
+; CHECK-NEXT: call void @use(i8 [[M2]])
+; CHECK-NEXT: [[M3:%.*]] = call i8 @llvm.smin.i8(i8 [[M1]], i8 [[M2]])
+; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[M3]], -1
+; CHECK-NEXT: ret i8 [[NOT]]
+;
+ %nx = xor i8 %x, -1
+ %ny = xor i8 %y, -1
+ %nz = xor i8 %z, -1
+ %nw = xor i8 %w, -1
+ call void @use(i8 %nx)
+ call void @use(i8 %ny)
+ call void @use(i8 %nz)
+ call void @use(i8 %nw)
+ %m1 = call i8 @llvm.umax.i8(i8 %nx, i8 %ny)
+ %m2 = call i8 @llvm.smax.i8(i8 %nw, i8 %nz)
+ call void @use(i8 %m2)
+ %m3 = call i8 @llvm.smin.i8(i8 %m1, i8 %m2)
+ %not = xor i8 %m3, -1
+ ret i8 %not
+}
+
+define i8 @freeToInvert_two_minmax_ops_use3(i8 %x, i8 %y, i8 %z, i8 %w) {
+; CHECK-LABEL: @freeToInvert_two_minmax_ops_use3(
+; CHECK-NEXT: [[NX:%.*]] = xor i8 [[X:%.*]], -1
+; CHECK-NEXT: [[NY:%.*]] = xor i8 [[Y:%.*]], -1
+; CHECK-NEXT: [[NZ:%.*]] = xor i8 [[Z:%.*]], -1
+; CHECK-NEXT: [[NW:%.*]] = xor i8 [[W:%.*]], -1
+; CHECK-NEXT: call void @use(i8 [[NX]])
+; CHECK-NEXT: call void @use(i8 [[NY]])
+; CHECK-NEXT: call void @use(i8 [[NZ]])
+; CHECK-NEXT: call void @use(i8 [[NW]])
+; CHECK-NEXT: [[M1:%.*]] = call i8 @llvm.umax.i8(i8 [[NX]], i8 [[NY]])
+; CHECK-NEXT: call void @use(i8 [[M1]])
+; CHECK-NEXT: [[M2:%.*]] = call i8 @llvm.smax.i8(i8 [[NW]], i8 [[NZ]])
+; CHECK-NEXT: call void @use(i8 [[M2]])
+; CHECK-NEXT: [[M3:%.*]] = call i8 @llvm.smin.i8(i8 [[M1]], i8 [[M2]])
+; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[M3]], -1
+; CHECK-NEXT: ret i8 [[NOT]]
+;
+ %nx = xor i8 %x, -1
+ %ny = xor i8 %y, -1
+ %nz = xor i8 %z, -1
+ %nw = xor i8 %w, -1
+ call void @use(i8 %nx)
+ call void @use(i8 %ny)
+ call void @use(i8 %nz)
+ call void @use(i8 %nw)
+ %m1 = call i8 @llvm.umax.i8(i8 %nx, i8 %ny)
+ call void @use(i8 %m1)
+ %m2 = call i8 @llvm.smax.i8(i8 %nw, i8 %nz)
+ call void @use(i8 %m2)
+ %m3 = call i8 @llvm.smin.i8(i8 %m1, i8 %m2)
+ %not = xor i8 %m3, -1
+ ret i8 %not
+}
+
declare void @use4(i8, i8, i8, i8)
define void @cmyk(i8 %r, i8 %g, i8 %b) {