[llvm] r207692 - [X86] Never hoist the shift value of a shift instruction.

Michael Zolotukhin mzolotukhin at apple.com
Wed Apr 30 12:17:32 PDT 2014


Author: mzolotukhin
Date: Wed Apr 30 14:17:32 2014
New Revision: 207692

URL: http://llvm.org/viewvc/llvm-project?rev=207692&view=rev
Log:
[X86] Never hoist the shift value of a shift instruction.

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

Added:
    llvm/trunk/test/Transforms/ConstantHoisting/X86/large-immediate.ll
Modified:
    llvm/trunk/lib/Target/X86/X86TargetTransformInfo.cpp
    llvm/trunk/test/CodeGen/X86/remat-invalid-liveness.ll

Modified: llvm/trunk/lib/Target/X86/X86TargetTransformInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86TargetTransformInfo.cpp?rev=207692&r1=207691&r2=207692&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86TargetTransformInfo.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86TargetTransformInfo.cpp Wed Apr 30 14:17:32 2014
@@ -956,15 +956,19 @@ unsigned X86TTI::getIntImmCost(unsigned
   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:

Modified: llvm/trunk/test/CodeGen/X86/remat-invalid-liveness.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/remat-invalid-liveness.ll?rev=207692&r1=207691&r2=207692&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/remat-invalid-liveness.ll (original)
+++ llvm/trunk/test/CodeGen/X86/remat-invalid-liveness.ll Wed Apr 30 14:17:32 2014
@@ -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:
   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

Added: llvm/trunk/test/Transforms/ConstantHoisting/X86/large-immediate.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/ConstantHoisting/X86/large-immediate.ll?rev=207692&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/ConstantHoisting/X86/large-immediate.ll (added)
+++ llvm/trunk/test/Transforms/ConstantHoisting/X86/large-immediate.ll Wed Apr 30 14:17:32 2014
@@ -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
+}





More information about the llvm-commits mailing list