[llvm] r365324 - [Float2Int] Add support for unary FNeg to Float2Int
Cameron McInally via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 8 07:46:07 PDT 2019
Author: mcinally
Date: Mon Jul 8 07:46:07 2019
New Revision: 365324
URL: http://llvm.org/viewvc/llvm-project?rev=365324&view=rev
Log:
[Float2Int] Add support for unary FNeg to Float2Int
Differential Revision: https://reviews.llvm.org/D63941
Modified:
llvm/trunk/lib/Transforms/Scalar/Float2Int.cpp
llvm/trunk/test/Transforms/Float2Int/basic.ll
Modified: llvm/trunk/lib/Transforms/Scalar/Float2Int.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/Float2Int.cpp?rev=365324&r1=365323&r2=365324&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/Float2Int.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/Float2Int.cpp Mon Jul 8 07:46:07 2019
@@ -200,6 +200,7 @@ void Float2IntPass::walkBackwards(const
continue;
}
+ case Instruction::FNeg:
case Instruction::FAdd:
case Instruction::FSub:
case Instruction::FMul:
@@ -240,6 +241,15 @@ void Float2IntPass::walkForwards() {
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 @@ Value *Float2IntPass::convert(Instructio
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:
Modified: llvm/trunk/test/Transforms/Float2Int/basic.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Float2Int/basic.ll?rev=365324&r1=365323&r2=365324&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/Float2Int/basic.ll (original)
+++ llvm/trunk/test/Transforms/Float2Int/basic.ll Mon Jul 8 07:46:07 2019
@@ -80,12 +80,11 @@ define i32 @simple5(i8 %a, i8 %b) {
}
; 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 @@ define i32 @simple_negative(i8 %call) {
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
;
More information about the llvm-commits
mailing list