File tree Expand file tree Collapse file tree 2 files changed +22
-7
lines changed
lib/Transforms/InstCombine
test/Transforms/InstCombine Expand file tree Collapse file tree 2 files changed +22
-7
lines changed Original file line number Diff line number Diff line change @@ -1923,17 +1923,36 @@ Instruction *InstCombinerImpl::foldItoFPtoI(CastInst &FI) {
1923
1923
return replaceInstUsesWith (FI, X);
1924
1924
}
1925
1925
1926
+ static Instruction *foldFPtoI (Instruction &FI, InstCombiner &IC) {
1927
+ // fpto{u/s}i non-norm --> 0
1928
+ FPClassTest Mask =
1929
+ FI.getOpcode () == Instruction::FPToUI ? fcPosNormal : fcNormal;
1930
+ KnownFPClass FPClass =
1931
+ computeKnownFPClass (FI.getOperand (0 ), Mask, /* Depth=*/ 0 ,
1932
+ IC.getSimplifyQuery ().getWithInstruction (&FI));
1933
+ if (FPClass.isKnownNever (Mask))
1934
+ return IC.replaceInstUsesWith (FI, ConstantInt::getNullValue (FI.getType ()));
1935
+
1936
+ return nullptr ;
1937
+ }
1938
+
1926
1939
Instruction *InstCombinerImpl::visitFPToUI (FPToUIInst &FI) {
1927
1940
if (Instruction *I = foldItoFPtoI (FI))
1928
1941
return I;
1929
1942
1943
+ if (Instruction *I = foldFPtoI (FI, *this ))
1944
+ return I;
1945
+
1930
1946
return commonCastTransforms (FI);
1931
1947
}
1932
1948
1933
1949
Instruction *InstCombinerImpl::visitFPToSI (FPToSIInst &FI) {
1934
1950
if (Instruction *I = foldItoFPtoI (FI))
1935
1951
return I;
1936
1952
1953
+ if (Instruction *I = foldFPtoI (FI, *this ))
1954
+ return I;
1955
+
1937
1956
return commonCastTransforms (FI);
1938
1957
}
1939
1958
Original file line number Diff line number Diff line change @@ -350,27 +350,23 @@ define double @masked_uint_to_fpext3(i32 %x) {
350
350
351
351
define i32 @fptosi_nonnorm (float nofpclass(norm) %x ) {
352
352
; CHECK-LABEL: @fptosi_nonnorm(
353
- ; CHECK-NEXT: [[RET:%.*]] = fptosi float [[X:%.*]] to i32
354
- ; CHECK-NEXT: ret i32 [[RET]]
353
+ ; CHECK-NEXT: ret i32 0
355
354
;
356
355
%ret = fptosi float %x to i32
357
356
ret i32 %ret
358
357
}
359
358
360
359
define i32 @fptoui_nonnorm (float nofpclass(pnorm) %x ) {
361
360
; CHECK-LABEL: @fptoui_nonnorm(
362
- ; CHECK-NEXT: [[RET:%.*]] = fptoui float [[X:%.*]] to i32
363
- ; CHECK-NEXT: ret i32 [[RET]]
361
+ ; CHECK-NEXT: ret i32 0
364
362
;
365
363
%ret = fptoui float %x to i32
366
364
ret i32 %ret
367
365
}
368
366
369
367
define i32 @fptosi_nonnorm_copysign (float %x ) {
370
368
; CHECK-LABEL: @fptosi_nonnorm_copysign(
371
- ; CHECK-NEXT: [[VAL:%.*]] = call float @llvm.copysign.f32(float 0.000000e+00, float [[X:%.*]])
372
- ; CHECK-NEXT: [[RET:%.*]] = fptosi float [[VAL]] to i32
373
- ; CHECK-NEXT: ret i32 [[RET]]
369
+ ; CHECK-NEXT: ret i32 0
374
370
;
375
371
%val = call float @llvm.copysign.f32 (float 0 .0 , float %x )
376
372
%ret = fptosi float %val to i32
You can’t perform that action at this time.
0 commit comments