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 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: 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 ;