From 6c2e8874b0f1fd993a17ad27c8348ae531cd5464 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Thu, 19 Jun 2014 07:14:33 +0000 Subject: InstCombine: Stop two transforms dueling InstCombineMulDivRem has: // Canonicalize (X+C1)*CI -> X*CI+C1*CI. InstCombineAddSub has: // W*X + Y*Z --> W * (X+Z) iff W == Y These two transforms could fight with each other if C1*CI would not fold away to something simpler than a ConstantExpr mul. The InstCombineMulDivRem transform only acted on ConstantInts until r199602 when it was changed to operate on all Constants in order to let it fire on ConstantVectors. To fix this, make this transform more careful by checking to see if we actually folded away C1*CI. This fixes PR20079. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211258 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Transforms/InstCombine/pr20079.ll | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 test/Transforms/InstCombine/pr20079.ll (limited to 'test') diff --git a/test/Transforms/InstCombine/pr20079.ll b/test/Transforms/InstCombine/pr20079.ll new file mode 100644 index 0000000000..3c86ecc5f3 --- /dev/null +++ b/test/Transforms/InstCombine/pr20079.ll @@ -0,0 +1,13 @@ +; RUN: opt -S -instcombine < %s | FileCheck %s +@b = internal global [1 x i32] zeroinitializer, align 4 +@c = internal global i32 0, align 4 + +; CHECK-LABEL: @fn1 +; CHECK: [[ADD:%.*]] = add i32 %a, -1 +; CHECK-NEXT: [[AND:%.*]] = and i32 [[ADD]], sub (i32 0, i32 zext (i1 icmp eq (i32* getelementptr inbounds ([1 x i32]* @b, i64 0, i64 0), i32* @c) to i32)) +; CHECK-NEXT: ret i32 [[AND]] +define i32 @fn1(i32 %a) { + %xor = add i32 %a, -1 + %mul = mul nsw i32 %xor, zext (i1 icmp eq (i32* getelementptr inbounds ([1 x i32]* @b, i64 0, i64 0), i32* @c) to i32) + ret i32 %mul +} -- cgit v1.2.3