[LLVMbugs] [Bug 4374] New: incorrect instcombine optimization

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Thu Jun 11 23:11:06 PDT 2009


http://llvm.org/bugs/show_bug.cgi?id=4374

           Summary: incorrect instcombine optimization
           Product: libraries
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Scalar Optimizations
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: llvm at laurentm.net
                CC: llvmbugs at cs.uiuc.edu


The following transfomation is incorrect: fsub(a,fsub(b,c)) =>
fadd(a,fsub(c,b))

For example:

float
func(float a, float b) {
    return -(a - b);
}

llvm-gcc generates:
define float @func(float %a, float %b) nounwind {
entry:
        %tmp3 = sub float %a, %b                ; <float> [#uses=1]
        %tmp4 = sub float -0.000000e+00, %tmp3          ; <float> [#uses=1]
        ret float %tmp4
}

opt -instcombine generates:
define float @func(float %a, float %b) nounwind {
entry:
        %tmp3 = sub float %b, %a                ; <float> [#uses=1]
        ret float %tmp3
}

The result of func(x,x) should be -0.0f not +0.0f.

InstructionCombining.cpp at 2621
    ...
    if (Op1I->hasOneUse()) {
      // Replace (x - (y - z)) with (x + (z - y)) if the (y - z) subexpression
      // is not used by anyone else...
      //
      if (Op1I->getOpcode() == Instruction::FSub) {
        // Swap the two operands of the subexpr...
        Value *IIOp0 = Op1I->getOperand(0), *IIOp1 = Op1I->getOperand(1);
        Op1I->setOperand(0, IIOp1);
        Op1I->setOperand(1, IIOp0);

        // Create the new top level fadd instruction...
        return BinaryOperator::CreateFAdd(Op0, Op1);
      }
    }
    ...


-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list