Skip to content

Commit c31be3c

Browse files
committed
[InstCombine] Address review comments.
1 parent 2b05c77 commit c31be3c

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3529,6 +3529,7 @@ Value *InstCombinerImpl::foldAndOrOfICmps(ICmpInst *LHS, ICmpInst *RHS,
35293529
if (LHS0 == RHS0 && PredL == PredR &&
35303530
PredL == (IsAnd ? ICmpInst::ICMP_NE : ICmpInst::ICMP_EQ) &&
35313531
!I.getFunction()->hasFnAttribute(Attribute::NoImplicitFloat) &&
3532+
LHS->hasOneUse() && RHS->hasOneUse() &&
35323533
match(LHS0, m_And(m_ElementWiseBitCast(m_Value(X)), m_APInt(MaskC))) &&
35333534
X->getType()->getScalarType()->isIEEELikeFPTy() &&
35343535
APFloat(X->getType()->getScalarType()->getFltSemantics(), *MaskC)

llvm/test/Transforms/InstCombine/fpclass-check-idioms.ll

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,20 @@ define i1 @fpclass_test_not_normal(float %num) {
10691069
ret i1 %res
10701070
}
10711071

1072+
define <2 x i1> @fpclass_test_not_normal_vec(<2 x float> %num) {
1073+
; CHECK-LABEL: define <2 x i1> @fpclass_test_not_normal_vec(
1074+
; CHECK-SAME: <2 x float> [[NUM:%.*]]) {
1075+
; CHECK-NEXT: [[RES:%.*]] = call <2 x i1> @llvm.is.fpclass.v2f32(<2 x float> [[NUM]], i32 759)
1076+
; CHECK-NEXT: ret <2 x i1> [[RES]]
1077+
;
1078+
%cast = bitcast <2 x float> %num to <2 x i32>
1079+
%masked = and <2 x i32> %cast, splat(i32 2139095040)
1080+
%test1 = icmp eq <2 x i32> %masked, splat(i32 2139095040)
1081+
%test2 = icmp eq <2 x i32> %masked, zeroinitializer
1082+
%res = or <2 x i1> %test1, %test2
1083+
ret <2 x i1> %res
1084+
}
1085+
10721086
define i1 @fpclass_test_normal_commuted(float %num) {
10731087
; CHECK-LABEL: define i1 @fpclass_test_normal_commuted(
10741088
; CHECK-SAME: float [[NUM:%.*]]) {
@@ -1083,6 +1097,26 @@ define i1 @fpclass_test_normal_commuted(float %num) {
10831097
ret i1 %res
10841098
}
10851099

1100+
; Negative tests
1101+
1102+
define i1 @fpclass_test_normal_fp128(ppc_fp128 %x) {
1103+
; CHECK-LABEL: define i1 @fpclass_test_normal_fp128(
1104+
; CHECK-SAME: ppc_fp128 [[X:%.*]]) {
1105+
; CHECK-NEXT: [[BITS:%.*]] = bitcast ppc_fp128 [[X]] to i128
1106+
; CHECK-NEXT: [[MASKED:%.*]] = and i128 [[BITS]], 170058106710732674489630815774616584192
1107+
; CHECK-NEXT: [[TEST1:%.*]] = icmp ne i128 [[MASKED]], 170058106710732674489630815774616584192
1108+
; CHECK-NEXT: [[TEST2:%.*]] = icmp ne i128 [[MASKED]], 0
1109+
; CHECK-NEXT: [[RES:%.*]] = and i1 [[TEST2]], [[TEST1]]
1110+
; CHECK-NEXT: ret i1 [[RES]]
1111+
;
1112+
%bits = bitcast ppc_fp128 %x to i128
1113+
%masked = and i128 %bits, 170058106710732674489630815774616584192
1114+
%test1 = icmp ne i128 %masked, 170058106710732674489630815774616584192
1115+
%test2 = icmp ne i128 %masked, 0
1116+
%res = and i1 %test2, %test1
1117+
ret i1 %res
1118+
}
1119+
10861120
define i1 @fpclass_test_normal_mismatch_pred(float %num) {
10871121
; CHECK-LABEL: define i1 @fpclass_test_normal_mismatch_pred(
10881122
; CHECK-SAME: float [[NUM:%.*]]) {
@@ -1169,6 +1203,27 @@ define i1 @fpclass_test_normal_invalid_constant3(float %num) {
11691203
ret i1 %res
11701204
}
11711205

1206+
define i1 @fpclass_test_normal_multiuse(float %num) {
1207+
; CHECK-LABEL: define i1 @fpclass_test_normal_multiuse(
1208+
; CHECK-SAME: float [[NUM:%.*]]) {
1209+
; CHECK-NEXT: [[CAST:%.*]] = bitcast float [[NUM]] to i32
1210+
; CHECK-NEXT: [[MASKED:%.*]] = and i32 [[CAST]], 2139095040
1211+
; CHECK-NEXT: [[TEST1:%.*]] = icmp ne i32 [[MASKED]], 2139095040
1212+
; CHECK-NEXT: [[TEST2:%.*]] = icmp ne i32 [[MASKED]], 0
1213+
; CHECK-NEXT: call void @usei1(i1 [[TEST1]])
1214+
; CHECK-NEXT: [[RES:%.*]] = and i1 [[TEST1]], [[TEST2]]
1215+
; CHECK-NEXT: ret i1 [[RES]]
1216+
;
1217+
%cast = bitcast float %num to i32
1218+
%masked = and i32 %cast, 2139095040
1219+
%test1 = icmp ne i32 %masked, 2139095040
1220+
%test2 = icmp ne i32 %masked, 0
1221+
call void @usei1(i1 %test1)
1222+
%res = and i1 %test1, %test2
1223+
ret i1 %res
1224+
}
1225+
11721226
declare void @usei32(i32)
1227+
declare void @usei1(i1)
11731228

11741229
attributes #0 = { noimplicitfloat }

0 commit comments

Comments
 (0)