[X86] Never hoist the shift value of a shift instruction.
authorMichael Zolotukhin <mzolotukhin@apple.com>
Wed, 30 Apr 2014 19:17:32 +0000 (19:17 +0000)
committerMichael Zolotukhin <mzolotukhin@apple.com>
Wed, 30 Apr 2014 19:17:32 +0000 (19:17 +0000)
There is no need to check if we want to hoist the immediate value of an
shift instruction. Simply return TCC_Free right away.

This change is like r206101, but for X86.

rdar://problem/16190769

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207692 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/X86TargetTransformInfo.cpp
test/CodeGen/X86/remat-invalid-liveness.ll
test/Transforms/ConstantHoisting/X86/large-immediate.ll [new file with mode: 0644]

index 1543f109b4cb486c24f1ae032540751ec4375770..ce060aba64446d36349d910bc8ada7e2dd5fa80a 100644 (file)
@@ -956,15 +956,19 @@ unsigned X86TTI::getIntImmCost(unsigned Opcode, unsigned Idx, const APInt &Imm,
   case Instruction::SDiv:
   case Instruction::URem:
   case Instruction::SRem:
-  case Instruction::Shl:
-  case Instruction::LShr:
-  case Instruction::AShr:
   case Instruction::And:
   case Instruction::Or:
   case Instruction::Xor:
   case Instruction::ICmp:
     ImmIdx = 1;
     break;
+  // Always return TCC_Free for the shift value of a shift instruction.
+  case Instruction::Shl:
+  case Instruction::LShr:
+  case Instruction::AShr:
+    if (Idx == 1)
+      return TCC_Free;
+    break;
   case Instruction::Trunc:
   case Instruction::ZExt:
   case Instruction::SExt:
index b14afe96ef43de841073511c0835eefae55f7154..d285e83b7981bd8a0f8539cf833db1085e7d65de 100644 (file)
@@ -31,6 +31,8 @@ target triple = "i386-apple-macosx10.9"
 ; Function Attrs: nounwind optsize ssp
 define fastcc void @__XXX1(%struct.A* %ht) #0 {
 entry:
+  %const72 = bitcast i128 72 to i128
+  %const3 = bitcast i128 3 to i128
   switch i32 undef, label %if.end196 [
     i32 1, label %sw.bb.i
     i32 3, label %sw.bb2.i
@@ -39,13 +41,13 @@ entry:
 sw.bb.i:                                          ; preds = %entry
   %call.i.i.i = tail call i32 undef(%struct.A* %ht, i8 zeroext 22, i32 undef, i32 0, %struct.D* undef)
   %bf.load.i.i = load i128* undef, align 4
-  %bf.lshr.i.i = lshr i128 %bf.load.i.i, 72
+  %bf.lshr.i.i = lshr i128 %bf.load.i.i, %const72
   %shl1.i.i = shl nuw nsw i128 %bf.lshr.i.i, 8
   %shl.i.i = trunc i128 %shl1.i.i to i32
   br i1 undef, label %cond.false10.i.i, label %__XXX2.exit.i.i
 
 __XXX2.exit.i.i:                    ; preds = %sw.bb.i
-  %extract11.i.i.i = lshr i128 %bf.load.i.i, 3
+  %extract11.i.i.i = lshr i128 %bf.load.i.i, %const3
   %extract.t12.i.i.i = trunc i128 %extract11.i.i.i to i32
   %bf.cast7.i.i.i = and i32 %extract.t12.i.i.i, 3
   %arrayidx.i.i.i = getelementptr inbounds %struct.A* %ht, i32 0, i32 3, i32 %bf.cast7.i.i.i
@@ -69,11 +71,11 @@ for.body.i.i:                                     ; preds = %for.body.i.i, %cond
   br i1 %or.cond, label %for.body.i.i, label %if.end196
 
 sw.bb2.i:                                         ; preds = %entry
-  %bf.lshr.i85.i = lshr i128 undef, 72
+  %bf.lshr.i85.i = lshr i128 undef, %const72
   br i1 undef, label %if.end196, label %__XXX2.exit.i95.i
 
 __XXX2.exit.i95.i:                  ; preds = %sw.bb2.i
-  %extract11.i.i91.i = lshr i128 undef, 3
+  %extract11.i.i91.i = lshr i128 undef, %const3
   br label %if.end196
 
 if.end196:                                        ; preds = %__XXX2.exit.i95.i, %sw.bb2.i, %for.body.i.i, %cond.end12.i.i, %entry
diff --git a/test/Transforms/ConstantHoisting/X86/large-immediate.ll b/test/Transforms/ConstantHoisting/X86/large-immediate.ll
new file mode 100644 (file)
index 0000000..bd7fa40
--- /dev/null
@@ -0,0 +1,18 @@
+; RUN: opt -mtriple=x86_64-darwin-unknown -S -consthoist < %s | FileCheck %s
+
+define i128 @test1(i128 %a) nounwind {
+; CHECK-LABEL: test1
+; CHECK: %const = bitcast i128 12297829382473034410122878 to i128
+  %1 = add i128 %a, 12297829382473034410122878
+  %2 = add i128 %1, 12297829382473034410122878
+  ret i128 %2
+}
+
+; Check that we don't hoist the shift value of a shift instruction.
+define i512 @test2(i512 %a) nounwind {
+; CHECK-LABEL: test2
+; CHECK-NOT: %const = bitcast i512 504 to i512
+  %1 = shl i512 %a, 504
+  %2 = ashr i512 %1, 504
+  ret i512 %2
+}