[llvm] r338204 - [X86] Correct the immediate cost for 'add/sub i64 %x, 0x80000000'.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 28 11:21:46 PDT 2018


Author: ctopper
Date: Sat Jul 28 11:21:46 2018
New Revision: 338204

URL: http://llvm.org/viewvc/llvm-project?rev=338204&view=rev
Log:
[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.

Modified:
    llvm/trunk/lib/Target/X86/X86TargetTransformInfo.cpp

Modified: llvm/trunk/lib/Target/X86/X86TargetTransformInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86TargetTransformInfo.cpp?rev=338204&r1=338203&r2=338204&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86TargetTransformInfo.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86TargetTransformInfo.cpp Sat Jul 28 11:21:46 2018
@@ -2332,9 +2332,15 @@ int X86TTIImpl::getIntImmCost(unsigned O
     // 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:




More information about the llvm-commits mailing list