From d6131c9633d3ea05b6aa51a3a2d9df2ec328bd67 Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Thu, 11 Oct 2018 23:14:35 +0000 Subject: X86/TargetTransformInfo: Report div/rem constant immediate costs as TCC_Free DIV/REM by constants should always be expanded into mul/shift/etc. patterns. Unfortunately the ConstantHoisting pass runs too early at a point where the pattern isn't expanded yet. However after ConstantHoisting hoisted some immediate the result may not expand anymore. Also the hoisting typically doesn't make sense because it operates on immediates that will change completely during the expansion. Report DIV/REM as TCC_Free so ConstantHoisting will not touch them. Differential Revision: https://reviews.llvm.org/D53174 llvm-svn: 344315 --- llvm/lib/Target/X86/X86TargetTransformInfo.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'llvm/lib') diff --git a/llvm/lib/Target/X86/X86TargetTransformInfo.cpp b/llvm/lib/Target/X86/X86TargetTransformInfo.cpp index 4c14715b758..d3a75123935 100644 --- a/llvm/lib/Target/X86/X86TargetTransformInfo.cpp +++ b/llvm/lib/Target/X86/X86TargetTransformInfo.cpp @@ -2342,11 +2342,15 @@ int X86TTIImpl::getIntImmCost(unsigned Opcode, unsigned Idx, const APInt &Imm, return TTI::TCC_Free; ImmIdx = 1; break; - case Instruction::Mul: case Instruction::UDiv: case Instruction::SDiv: case Instruction::URem: case Instruction::SRem: + // Division by constant is typically expanded later into a different + // instruction sequence. This completely changes the constants. + // Report them as "free" to stop ConstantHoist from marking them as opaque. + return TTI::TCC_Free; + case Instruction::Mul: case Instruction::Or: case Instruction::Xor: ImmIdx = 1; -- cgit v1.2.3