> You should check out the -enable-finite-only-fp-math and -enable-unsafe-fp-math options.Good hint, but llvm::UnsafeFPMath = true; llvm::FiniteOnlyFPMathOption = true; at the beginning of my code does not help. I found llvm::Reassociate::OptimizeExpression in llvm\lib\Transforms\Scalar\Reassociate.cpp which looks like it does X * 0 = 0 for int, but it does not get called for int, but it works for int. -Jochen
On Mar 3, 2010, at 10:23 AM, Jochen Wilhelmy wrote:> >> You should check out the -enable-finite-only-fp-math and -enable-unsafe-fp-math options. > > Good hint, but > > llvm::UnsafeFPMath = true; > llvm::FiniteOnlyFPMathOption = true; > > at the beginning of my code does not help. > I found llvm::Reassociate::OptimizeExpression in > llvm\lib\Transforms\Scalar\Reassociate.cpp > which looks like it does X * 0 = 0 for int, but it does not get called > for int, > but it works for int.These flags only affect the code generator. If you want to add this optimization to your copy of llvm, you can do so by adding it to the instcombine pass. We'd need IR enhancements to do this sort of thing for real in the mid-level optimizer, some thoughts are here: http://nondot.org/sabre/LLVMNotes/FloatingPointChanges.txt However, this is far from being a concrete proposal. -Chris
> These flags only affect the code generator. If you want to add this optimization to your copy of llvm, you can do so by adding it to the instcombine pass. We'd need IR enhancements to do this sort of thing for real in the mid-level optimizer, some thoughts are here: > http://nondot.org/sabre/LLVMNotes/FloatingPointChanges.txt >Thanks, now it works. I inserted if (Op1F->isNullValue()) return ReplaceInstUsesWith(I, Op1C); // X * 0 == 0 into llvm::InstCombiner::visitFMul Why not at first create a compile time option for this so that the code is already available for special purposes? -Jochen