From: Craig Topper Date: Sat, 28 Jul 2018 18:21:46 +0000 (+0000) Subject: [X86] Correct the immediate cost for 'add/sub i64 %x, 0x80000000'. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e192af49a170ac54aadc8cb75b9e88ac2d54e937;p=llvm [X86] Correct the immediate cost for 'add/sub i64 %x, 0x80000000'. X86 normally requires immediates to be a signed 32-bit value which would exclude i64 0x80000000. But for add/sub we can negate the constant and use the opposite instruction. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@338204 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Target/X86/X86TargetTransformInfo.cpp b/lib/Target/X86/X86TargetTransformInfo.cpp index 1b260d8d45d..0257c42def2 100644 --- a/lib/Target/X86/X86TargetTransformInfo.cpp +++ b/lib/Target/X86/X86TargetTransformInfo.cpp @@ -2332,9 +2332,15 @@ int X86TTIImpl::getIntImmCost(unsigned Opcode, unsigned Idx, const APInt &Imm, // immediates here as the normal path expects bit 31 to be sign extended. if (Idx == 1 && Imm.getBitWidth() == 64 && isUInt<32>(Imm.getZExtValue())) return TTI::TCC_Free; - LLVM_FALLTHROUGH; + ImmIdx = 1; + break; case Instruction::Add: case Instruction::Sub: + // For add/sub, we can use the opposite instruction for INT32_MIN. + if (Idx == 1 && Imm.getBitWidth() == 64 && isInt<32>(-Imm.getSExtValue())) + return TTI::TCC_Free; + ImmIdx = 1; + break; case Instruction::Mul: case Instruction::UDiv: case Instruction::SDiv: