Index: lib/Analysis/InstructionSimplify.cpp =================================================================== --- lib/Analysis/InstructionSimplify.cpp +++ lib/Analysis/InstructionSimplify.cpp @@ -1127,6 +1127,10 @@ if (match(Op1, m_Undef())) return Op1; + // X / 1.0 -> X + if (match(Op1, m_FPOne())) + return Op0; + // 0 / X -> 0 // Requires that NaNs are off (X could be zero) and signed zeroes are // ignored (X could be positive or negative, so the output sign is unknown). @@ -4093,6 +4097,8 @@ return SimplifyFSubInst(LHS, RHS, FMF, Q, MaxRecurse); case Instruction::FMul: return SimplifyFMulInst(LHS, RHS, FMF, Q, MaxRecurse); + case Instruction::FDiv: + return SimplifyFDivInst(LHS, RHS, FMF, Q, MaxRecurse); default: return SimplifyBinOp(Opcode, LHS, RHS, Q, MaxRecurse); } Index: test/Transforms/EarlyCSE/instsimplify-fdiv.ll =================================================================== --- test/Transforms/EarlyCSE/instsimplify-fdiv.ll +++ test/Transforms/EarlyCSE/instsimplify-fdiv.ll @@ -0,0 +1,19 @@ +; RUN: opt -O3 -S -mtriple=i686-pc-linux -print-after=early-cse < %s 2>&1 | FileCheck %s +; +; Check to make sure divide by 1.0 is simplified in early-cse. +; + +define double @foo(double %x, i32 %n, double %e) #0 { +entry: + %x.addr = alloca double, align 8 + %n.addr = alloca i32, align 4 + %e.addr = alloca double, align 8 + store double %x, double* %x.addr, align 8 + store i32 %n, i32* %n.addr, align 4 + store double %e, double* %e.addr, align 8 + %0 = load double, double* %x.addr, align 8 + %div = fdiv double %0, 1.000000e+00 + ret double %div +} + +; CHECK-NOT: fdiv