diff --git a/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp b/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp index d1302c6e22f..79624b2e4c4 100644 --- a/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp +++ b/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp @@ -113,10 +113,11 @@ bool CorrelatedValuePropagation::processPHI(PHINode *P) { Value *Condition = SI->getCondition(); if (!Condition->getType()->isVectorTy()) { - if (Constant *C = LVI->getConstantOnEdge(Condition, P->getIncomingBlock(i), BB, P)) { - if (C == ConstantInt::getTrue(Condition->getType())) { + if (Constant *C = LVI->getConstantOnEdge( + Condition, P->getIncomingBlock(i), BB, P)) { + if (C->isOneValue()) { V = SI->getTrueValue(); - } else { + } else if (C->isZeroValue()) { V = SI->getFalseValue(); } // Once LVI learns to handle vector types, we could also add support diff --git a/test/Transforms/CorrelatedValuePropagation/select.ll b/test/Transforms/CorrelatedValuePropagation/select.ll index 5501438f690..d88e3e462a2 100644 --- a/test/Transforms/CorrelatedValuePropagation/select.ll +++ b/test/Transforms/CorrelatedValuePropagation/select.ll @@ -51,3 +51,25 @@ else: ret i8 %b } +@c = global i32 0, align 4 +@b = global i32 0, align 4 + +; CHECK-LABEL: @PR23752( +define i32 @PR23752() { +entry: + br label %for.body + +for.body: + %phi = phi i32 [ 0, %entry ], [ %sel, %for.body ] + %sel = select i1 icmp sgt (i32* @b, i32* @c), i32 %phi, i32 1 + %cmp = icmp ne i32 %sel, 1 + br i1 %cmp, label %for.body, label %if.end + +; CHECK: %[[sel:.*]] = select i1 icmp sgt (i32* @b, i32* @c), i32 0, i32 1 +; CHECK-NEXT: %[[cmp:.*]] = icmp ne i32 %[[sel]], 1 +; CHECK-NEXT: br i1 %[[cmp]] + +if.end: + ret i32 %sel +; CHECK: ret i32 %[[sel]] +}