[PATCH] D63941: [Float2Int] Add support for unary FNeg to Float2Int
Phabricator via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 8 07:49:21 PDT 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rL365324: [Float2Int] Add support for unary FNeg to Float2Int (authored by mcinally, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D63941?vs=207090&id=208414#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D63941/new/
https://reviews.llvm.org/D63941
Files:
llvm/trunk/lib/Transforms/Scalar/Float2Int.cpp
llvm/trunk/test/Transforms/Float2Int/basic.ll
Index: llvm/trunk/test/Transforms/Float2Int/basic.ll
===================================================================
--- llvm/trunk/test/Transforms/Float2Int/basic.ll
+++ llvm/trunk/test/Transforms/Float2Int/basic.ll
@@ -80,12 +80,11 @@
}
; CHECK-LABEL: @simple6
-; CHECK: %1 = uitofp i8 %a to float
-; CHECK: %2 = uitofp i8 %b to float
-; CHECK: %3 = fneg float %1
-; CHECK: %4 = fmul float %3, %2
-; CHECK: %5 = fptoui float %4 to i32
-; CHECK: ret i32 %5
+; CHECK: %1 = zext i8 %a to i32
+; CHECK: %2 = zext i8 %b to i32
+; CHECK: %3 = sub i32 0, %1
+; CHECK: %4 = mul i32 %3, %2
+; CHECK: ret i32 %4
define i32 @simple6(i8 %a, i8 %b) {
%1 = uitofp i8 %a to float
%2 = uitofp i8 %b to float
@@ -145,6 +144,18 @@
ret i32 %conv3
}
+; CHECK-LABEL: @simple_fneg
+; CHECK: %1 = zext i8 %a to i32
+; CHECK: %2 = sub i32 0, %1
+; CHECK: %3 = trunc i32 %2 to i16
+; CHECK: ret i16 %3
+define i16 @simple_fneg(i8 %a) {
+ %1 = uitofp i8 %a to float
+ %2 = fneg fast float %1
+ %3 = fptoui float %2 to i16
+ ret i16 %3
+}
+
;
; Negative tests
;
Index: llvm/trunk/lib/Transforms/Scalar/Float2Int.cpp
===================================================================
--- llvm/trunk/lib/Transforms/Scalar/Float2Int.cpp
+++ llvm/trunk/lib/Transforms/Scalar/Float2Int.cpp
@@ -200,6 +200,7 @@
continue;
}
+ case Instruction::FNeg:
case Instruction::FAdd:
case Instruction::FSub:
case Instruction::FMul:
@@ -240,6 +241,15 @@
case Instruction::SIToFP:
llvm_unreachable("Should have been handled in walkForwards!");
+ case Instruction::FNeg:
+ Op = [](ArrayRef<ConstantRange> Ops) {
+ assert(Ops.size() == 1 && "FNeg is a unary operator!");
+ unsigned Size = Ops[0].getBitWidth();
+ auto Zero = ConstantRange(APInt::getNullValue(Size));
+ return Zero.sub(Ops[0]);
+ };
+ break;
+
case Instruction::FAdd:
case Instruction::FSub:
case Instruction::FMul:
@@ -466,6 +476,10 @@
NewV = IRB.CreateSExtOrTrunc(NewOperands[0], ToTy);
break;
+ case Instruction::FNeg:
+ NewV = IRB.CreateNeg(NewOperands[0], I->getName());
+ break;
+
case Instruction::FAdd:
case Instruction::FSub:
case Instruction::FMul:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63941.208414.patch
Type: text/x-patch
Size: 2258 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190708/84ab8b26/attachment.bin>
More information about the llvm-commits
mailing list