diff options
-rw-r--r-- | lib/Transforms/InstCombine/InstCombineAddSub.cpp | 5 | ||||
-rw-r--r-- | test/Transforms/InstCombine/mul.ll | 5 | ||||
-rw-r--r-- | test/Transforms/InstCombine/zext-bool-add-sub.ll | 39 |
3 files changed, 16 insertions, 33 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/lib/Transforms/InstCombine/InstCombineAddSub.cpp index 00f9974..99b62f8 100644 --- a/lib/Transforms/InstCombine/InstCombineAddSub.cpp +++ b/lib/Transforms/InstCombine/InstCombineAddSub.cpp @@ -544,11 +544,6 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) { if (Instruction *R = FoldOpIntoSelect(I, SI)) return R; - // C - zext(bool) -> bool ? C - 1 : C - if (ZExtInst *ZI = dyn_cast<ZExtInst>(Op1)) - if (ZI->getSrcTy()->isIntegerTy(1)) - return SelectInst::Create(ZI->getOperand(0), SubOne(C), C); - // C-(X+C2) --> (C-C2)-X ConstantInt *C2; if (match(Op1, m_Add(m_Value(X), m_ConstantInt(C2)))) diff --git a/test/Transforms/InstCombine/mul.ll b/test/Transforms/InstCombine/mul.ll index edb5305..6c8e634 100644 --- a/test/Transforms/InstCombine/mul.ll +++ b/test/Transforms/InstCombine/mul.ll @@ -138,8 +138,9 @@ define i32 @test16(i32 %b, i1 %c) { ; e = b & (a >> 31) %e = mul i32 %d, %b ; <i32> [#uses=1] ret i32 %e -; CHECK: [[TEST16:%.*]] = sext i1 %c to i32 -; CHECK-NEXT: %e = and i32 [[TEST16]], %b +; CHECK: [[TEST16:%.*]] = zext i1 %c to i32 +; CHECK-NEXT: %1 = sub i32 0, [[TEST16]] +; CHECK-NEXT: %e = and i32 %1, %b ; CHECK-NEXT: ret i32 %e } diff --git a/test/Transforms/InstCombine/zext-bool-add-sub.ll b/test/Transforms/InstCombine/zext-bool-add-sub.ll index 1164273..78bcedb 100644 --- a/test/Transforms/InstCombine/zext-bool-add-sub.ll +++ b/test/Transforms/InstCombine/zext-bool-add-sub.ll @@ -1,29 +1,16 @@ -; RUN: opt < %s -instcombine -S | not grep zext +; RUN: opt < %s -instcombine -S | FileCheck %s +; rdar://11748024 -define i32 @a(i1 %x) { +define i32 @a(i1 zeroext %x, i1 zeroext %y) { entry: - %y = zext i1 %x to i32 - %res = add i32 %y, 1 - ret i32 %res -} - -define i32 @b(i1 %x) { -entry: - %y = zext i1 %x to i32 - %res = add i32 %y, -1 - ret i32 %res -} - -define i32 @c(i1 %x) { -entry: - %y = zext i1 %x to i32 - %res = sub i32 0, %y - ret i32 %res -} - -define i32 @d(i1 %x) { -entry: - %y = zext i1 %x to i32 - %res = sub i32 3, %y - ret i32 %res +; CHECK: @a +; CHECK: [[TMP1:%.*]] = zext i1 %y to i32 +; CHECK: [[TMP2:%.*]] = select i1 %x, i32 2, i32 1 +; CHECK-NEXT: sub i32 [[TMP2]], [[TMP1]] + %conv = zext i1 %x to i32 + %conv3 = zext i1 %y to i32 + %conv3.neg = sub i32 0, %conv3 + %sub = add i32 %conv, 1 + %add = add i32 %sub, %conv3.neg + ret i32 %add } |