[llvm-commits] [llvm] r168848 - in /llvm/trunk: include/llvm/Instruction.h lib/VMCore/Instruction.cpp test/Transforms/InstCombine/fast-math.ll

Michael Ilseman milseman at apple.com
Thu Nov 29 11:36:25 PST 2012


> +define float @fold2(float %a) {
> +notfold2:
> +; CHECK: fold2
> +; CHECK: fmul float %a, 0x4006147AE0000000
> +  %mul = fmul float %a, 0x3FF3333340000000
> +  %mul1 = fmul fast float %mul, 0x4002666660000000
> +  ret float %mul1
> +}

If you just have one block, there's no need to name the entry block. If you do want to name the entry block, then I'd recommend something that isn't the function name, so that it doesn't fall out of date. Here it's named "notfold2" while the function's name is "fold2" :)


On Nov 28, 2012, at 5:47 PM, Shuxin Yang <shuxin.llvm at gmail.com> wrote:

> Author: shuxin_yang
> Date: Wed Nov 28 19:47:31 2012
> New Revision: 168848
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=168848&view=rev
> Log:
> Instruction::isAssociative() returns true for fmul/fadd if they are tagged "unsafe" mode.
> 
> Approved by: Eli and Michael.
> 
> Added:
>    llvm/trunk/test/Transforms/InstCombine/fast-math.ll
> Modified:
>    llvm/trunk/include/llvm/Instruction.h
>    llvm/trunk/lib/VMCore/Instruction.cpp
> 
> Modified: llvm/trunk/include/llvm/Instruction.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Instruction.h?rev=168848&r1=168847&r2=168848&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/Instruction.h (original)
> +++ llvm/trunk/include/llvm/Instruction.h Wed Nov 28 19:47:31 2012
> @@ -253,7 +253,7 @@
>   ///
>   /// In LLVM, the Add, Mul, And, Or, and Xor operators are associative.
>   ///
> -  bool isAssociative() const { return isAssociative(getOpcode()); }
> +  bool isAssociative() const;
>   static bool isAssociative(unsigned op);
> 
>   /// isCommutative - Return true if the instruction is commutative:
> 
> Modified: llvm/trunk/lib/VMCore/Instruction.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Instruction.cpp?rev=168848&r1=168847&r2=168848&view=diff
> ==============================================================================
> --- llvm/trunk/lib/VMCore/Instruction.cpp (original)
> +++ llvm/trunk/lib/VMCore/Instruction.cpp Wed Nov 28 19:47:31 2012
> @@ -468,6 +468,20 @@
>          Opcode == Add || Opcode == Mul;
> }
> 
> +bool Instruction::isAssociative() const {
> +  unsigned Opcode = getOpcode();
> +  if (isAssociative(Opcode))
> +    return true;
> +
> +  switch (Opcode) {
> +  case FMul:
> +  case FAdd:
> +    return cast<FPMathOperator>(this)->hasUnsafeAlgebra();
> +  default:
> +    return false;
> +  }
> +}
> +
> /// isCommutative - Return true if the instruction is commutative:
> ///
> ///   Commutative operators satisfy: (x op y) === (y op x)
> 
> Added: llvm/trunk/test/Transforms/InstCombine/fast-math.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/fast-math.ll?rev=168848&view=auto
> ==============================================================================
> --- llvm/trunk/test/Transforms/InstCombine/fast-math.ll (added)
> +++ llvm/trunk/test/Transforms/InstCombine/fast-math.ll Wed Nov 28 19:47:31 2012
> @@ -0,0 +1,32 @@
> +; RUN: opt < %s -instcombine -S | FileCheck %s
> +
> +; testing-case "float fold(float a) { return 1.2f * a * 2.3f; }"
> +; 1.2f and 2.3f is supposed to be fold.
> +define float @fold(float %a) {
> +fold:
> +  %mul = fmul fast float %a, 0x3FF3333340000000
> +  %mul1 = fmul fast float %mul, 0x4002666660000000
> +  ret float %mul1
> +; CHECK: fold
> +; CHECK: fmul float %a, 0x4006147AE0000000
> +}
> +
> +; Same testing-case as the one used in fold() except that the operators have
> +; fixed FP mode.
> +define float @notfold(float %a) {
> +notfold:
> +; CHECK: notfold
> +; CHECK: %mul = fmul fast float %a, 0x3FF3333340000000
> +  %mul = fmul fast float %a, 0x3FF3333340000000
> +  %mul1 = fmul float %mul, 0x4002666660000000
> +  ret float %mul1
> +}
> +
> +define float @fold2(float %a) {
> +notfold2:
> +; CHECK: fold2
> +; CHECK: fmul float %a, 0x4006147AE0000000
> +  %mul = fmul float %a, 0x3FF3333340000000
> +  %mul1 = fmul fast float %mul, 0x4002666660000000
> +  ret float %mul1
> +}
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list