From 12bb40b2ab9d66faa53bf83c07edfc00fea3a1d3 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Wed, 24 Jun 2015 21:52:25 +0000 Subject: [PATCH] [GVN] Intersect the IR flags when CSE'ing two instructions We performed a simple, but incomplete, intersection when it came time to CSE instructions. It didn't handle, for example, the 'exact' flag. This fixes PR23922. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240595 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/GVN.cpp | 10 +++------- test/Transforms/GVN/pr12979.ll | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/Transforms/Scalar/GVN.cpp b/lib/Transforms/Scalar/GVN.cpp index 6aee033b5dc..e93833c32f4 100644 --- a/lib/Transforms/Scalar/GVN.cpp +++ b/lib/Transforms/Scalar/GVN.cpp @@ -1783,13 +1783,9 @@ static void patchReplacementInstruction(Instruction *I, Value *Repl) { // being replaced. BinaryOperator *Op = dyn_cast(I); BinaryOperator *ReplOp = dyn_cast(Repl); - if (Op && ReplOp && isa(Op) && - isa(ReplOp)) { - if (ReplOp->hasNoSignedWrap() && !Op->hasNoSignedWrap()) - ReplOp->setHasNoSignedWrap(false); - if (ReplOp->hasNoUnsignedWrap() && !Op->hasNoUnsignedWrap()) - ReplOp->setHasNoUnsignedWrap(false); - } + if (Op && ReplOp) + ReplOp->andIRFlags(Op); + if (Instruction *ReplInst = dyn_cast(Repl)) { // FIXME: If both the original and replacement value are part of the // same control-flow region (meaning that the execution of one diff --git a/test/Transforms/GVN/pr12979.ll b/test/Transforms/GVN/pr12979.ll index 0198a56513e..919c22de02a 100644 --- a/test/Transforms/GVN/pr12979.ll +++ b/test/Transforms/GVN/pr12979.ll @@ -77,3 +77,17 @@ define i32 @test7(i32 %x, i32 %y) { %foo = add i32 %add1, %add2 ret i32 %foo } + +declare void @mumble(i2, i2) + +define void @test8(i2 %x) { +; CHECK-LABEL: @test8( +; CHECK: %[[ashr:.*]] = ashr i2 %x, 1 +; CHECK-NEXT: call void @mumble(i2 %[[ashr]], i2 %[[ashr]]) +; CHECK-NEXT: ret void + + %ashr0 = ashr exact i2 %x, 1 + %ashr1 = ashr i2 %x, 1 + call void @mumble(i2 %ashr0, i2 %ashr1) + ret void +} -- 2.34.1