[llvm-commits] [llvm] r158946 - in /llvm/trunk: lib/Transforms/InstCombine/InstCombineMulDivRem.cpp test/Transforms/InstCombine/div-shift.ll test/Transforms/InstCombine/sdiv-shift.ll
Evan Cheng
evan.cheng at apple.com
Thu Jun 21 15:52:49 PDT 2012
Author: evancheng
Date: Thu Jun 21 17:52:49 2012
New Revision: 158946
URL: http://llvm.org/viewvc/llvm-project?rev=158946&view=rev
Log:
Look pass zext to strength reduce an udiv. Patch by David Majnemer. rdar://11721329
Added:
llvm/trunk/test/Transforms/InstCombine/div-shift.ll
Removed:
llvm/trunk/test/Transforms/InstCombine/sdiv-shift.ll
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp?rev=158946&r1=158945&r2=158946&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp Thu Jun 21 17:52:49 2012
@@ -464,9 +464,12 @@
// X udiv (C1 << N), where C1 is "1<<C2" --> X >> (N+C2)
{ const APInt *CI; Value *N;
- if (match(Op1, m_Shl(m_Power2(CI), m_Value(N)))) {
+ if (match(Op1, m_Shl(m_Power2(CI), m_Value(N))) ||
+ match(Op1, m_ZExt(m_Shl(m_Power2(CI), m_Value(N))))) {
if (*CI != 1)
N = Builder->CreateAdd(N, ConstantInt::get(I.getType(),CI->logBase2()));
+ if (ZExtInst *Z = dyn_cast<ZExtInst>(Op1))
+ N = Builder->CreateZExt(N, Z->getDestTy());
if (I.isExact())
return BinaryOperator::CreateExactLShr(Op0, N);
return BinaryOperator::CreateLShr(Op0, N);
Added: llvm/trunk/test/Transforms/InstCombine/div-shift.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/div-shift.ll?rev=158946&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/div-shift.ll (added)
+++ llvm/trunk/test/Transforms/InstCombine/div-shift.ll Thu Jun 21 17:52:49 2012
@@ -0,0 +1,23 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+define i32 @t1(i16 zeroext %x, i32 %y) nounwind {
+entry:
+; CHECK: t1
+; CHECK-NOT: sdiv
+; CHECK: lshr i32 %conv
+ %conv = zext i16 %x to i32
+ %s = shl i32 2, %y
+ %d = sdiv i32 %conv, %s
+ ret i32 %d
+}
+
+; rdar://11721329
+define i64 @t2(i64 %x, i32 %y) nounwind {
+; CHECK: t2
+; CHECK-NOT: udiv
+; CHECK: lshr i64 %x
+ %1 = shl i32 1, %y
+ %2 = zext i32 %1 to i64
+ %3 = udiv i64 %x, %2
+ ret i64 %3
+}
Removed: llvm/trunk/test/Transforms/InstCombine/sdiv-shift.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/sdiv-shift.ll?rev=158945&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/sdiv-shift.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/sdiv-shift.ll (removed)
@@ -1,9 +0,0 @@
-; RUN: opt < %s -instcombine -S | not grep div
-
-define i32 @a(i16 zeroext %x, i32 %y) nounwind {
-entry:
- %conv = zext i16 %x to i32
- %s = shl i32 2, %y
- %d = sdiv i32 %conv, %s
- ret i32 %d
-}
More information about the llvm-commits
mailing list