From: Davide Italiano Date: Mon, 17 Apr 2017 20:49:50 +0000 (+0000) Subject: [InstCombine] Matchers work with both ConstExpr and Instructions. X-Git-Tag: llvmorg-5.0.0-rc1~7514 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cdc937d0fc14315836b471834fec2ff341de240f;p=platform%2Fupstream%2Fllvm.git [InstCombine] Matchers work with both ConstExpr and Instructions. So, `cast` is not guaranteed to succeed. Change the code so that we create a new constant and use it in the newly created instruction, as it's done in other places in InstCombine. OK'ed by Sanjay/Craig. Fixes PR32686. llvm-svn: 300495 --- diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp index b2a41c6..2906d34 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -2078,7 +2078,7 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) { Value *NOr = Builder->CreateOr(A, Op1); NOr->takeName(Op0); return BinaryOperator::CreateXor(NOr, - cast(Op0)->getOperand(1)); + ConstantInt::get(NOr->getType(), *C)); } // Y|(X^C) -> (X|Y)^C iff Y&C == 0 @@ -2087,7 +2087,7 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) { Value *NOr = Builder->CreateOr(A, Op0); NOr->takeName(Op0); return BinaryOperator::CreateXor(NOr, - cast(Op1)->getOperand(1)); + ConstantInt::get(NOr->getType(), *C)); } } diff --git a/llvm/test/Transforms/InstCombine/pr32686.ll b/llvm/test/Transforms/InstCombine/pr32686.ll new file mode 100644 index 0000000..7abda23 --- /dev/null +++ b/llvm/test/Transforms/InstCombine/pr32686.ll @@ -0,0 +1,22 @@ +; RUN: opt -S -instcombine %s | FileCheck %s + +; CHECK-LABEL: define void @tinkywinky +; CHECK-NEXT: %patatino = load i8, i8* @a, align 1 +; CHECK-NEXT: %tobool = icmp eq i8 %patatino, 0 +; CHECK-NEXT: %1 = zext i1 %tobool to i32 +; CHECK-NEXT: %or1 = or i32 %1, or (i32 zext (i1 icmp ne (i32* bitcast (i8* @a to i32*), i32* @b) to i32), i32 2) +; CHECK-NEXT: store i32 %or1, i32* @b, align 4 +; CHECK-NEXT: ret void + +@a = external global i8 +@b = external global i32 + +define void @tinkywinky() { + %patatino = load i8, i8* @a + %tobool = icmp ne i8 %patatino, 0 + %lnot = xor i1 %tobool, true + %lnot.ext = zext i1 %lnot to i32 + %or = or i32 xor (i32 zext (i1 icmp ne (i32* bitcast (i8* @a to i32*), i32* @b) to i32), i32 2), %lnot.ext + store i32 %or, i32* @b, align 4 + ret void +}