diff --git a/compiler-rt/test/dfsan/conditional_callbacks.c b/compiler-rt/test/dfsan/conditional_callbacks.c --- a/compiler-rt/test/dfsan/conditional_callbacks.c +++ b/compiler-rt/test/dfsan/conditional_callbacks.c @@ -80,7 +80,8 @@ if (DataI) { result = 42; } - + + fprintf(stderr, "Result is %d\n", result); assert(dfsan_get_label(DataJ) == LabelJ); // CHECK: Label 2 used as condition @@ -96,11 +97,13 @@ } int tainted_cond = ((DataI * DataJ) != 1); + fprintf(stderr, "Result is %d\n", result); assert(dfsan_get_label(tainted_cond) == LabelIJ); // CHECK: Label 3 used as condition result = tainted_cond ? result + 420000 : 9; + fprintf(stderr, "Result is %d\n", result); assert(result == 424242); return 0; } diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -3893,12 +3893,8 @@ Constant::getNullValue(LHSI->getOperand(0)->getType())); break; case Instruction::PHI: - // Only fold icmp into the PHI if the phi and icmp are in the same - // block. If in the same block, we're encouraging jump threading. If - // not, we are just pessimizing the code by making an i1 phi. - if (LHSI->getParent() == I.getParent()) - if (Instruction *NV = foldOpIntoPhi(I, cast(LHSI))) - return NV; + if (Instruction *NV = foldOpIntoPhi(I, cast(LHSI))) + return NV; break; case Instruction::IntToPtr: // icmp pred inttoptr(X), null -> icmp pred X, 0 @@ -7576,12 +7572,8 @@ if (match(Op0, m_Instruction(LHSI)) && match(Op1, m_Constant(RHSC))) { switch (LHSI->getOpcode()) { case Instruction::PHI: - // Only fold fcmp into the PHI if the phi and fcmp are in the same - // block. If in the same block, we're encouraging jump threading. If - // not, we are just pessimizing the code by making an i1 phi. - if (LHSI->getParent() == I.getParent()) - if (Instruction *NV = foldOpIntoPhi(I, cast(LHSI))) - return NV; + if (Instruction *NV = foldOpIntoPhi(I, cast(LHSI))) + return NV; break; case Instruction::SIToFP: case Instruction::UIToFP: diff --git a/llvm/test/Transforms/InstCombine/icmp-constant-phi.ll b/llvm/test/Transforms/InstCombine/icmp-constant-phi.ll --- a/llvm/test/Transforms/InstCombine/icmp-constant-phi.ll +++ b/llvm/test/Transforms/InstCombine/icmp-constant-phi.ll @@ -199,11 +199,9 @@ ; CHECK: if.false: ; CHECK-NEXT: br label [[MERGE]] ; CHECK: merge: -; CHECK-NEXT: [[PHI:%.*]] = phi float [ 1.000000e+00, [[IF_TRUE]] ], [ 1.250000e+00, [[IF_FALSE]] ] ; CHECK-NEXT: br label [[EXIT:%.*]] ; CHECK: exit: -; CHECK-NEXT: [[COMPARE:%.*]] = fcmp one float [[PHI]], 1.250000e+00 -; CHECK-NEXT: ret i1 [[COMPARE]] +; CHECK-NEXT: ret i1 [[COND]] ; entry: br i1 %cond, label %if.true, label %if.false @@ -263,11 +261,10 @@ ; CHECK: if.false: ; CHECK-NEXT: br label [[MERGE]] ; CHECK: merge: -; CHECK-NEXT: [[PHI:%.*]] = phi <2 x float> [ , [[IF_TRUE]] ], [ , [[IF_FALSE]] ] +; CHECK-NEXT: [[PHI:%.*]] = phi <2 x i1> [ , [[IF_TRUE]] ], [ , [[IF_FALSE]] ] ; CHECK-NEXT: br label [[EXIT:%.*]] ; CHECK: exit: -; CHECK-NEXT: [[COMPARE:%.*]] = fcmp one <2 x float> [[PHI]], -; CHECK-NEXT: ret <2 x i1> [[COMPARE]] +; CHECK-NEXT: ret <2 x i1> [[PHI]] ; entry: br i1 %cond, label %if.true, label %if.false diff --git a/llvm/test/Transforms/InstCombine/phi.ll b/llvm/test/Transforms/InstCombine/phi.ll --- a/llvm/test/Transforms/InstCombine/phi.ll +++ b/llvm/test/Transforms/InstCombine/phi.ll @@ -2304,27 +2304,24 @@ ; CHECK-NEXT: [[INCDEC_PTR_I]] = getelementptr inbounds i8, ptr [[TEST_0_I]], i64 1 ; CHECK-NEXT: br i1 [[CMP1_NOT_I]], label [[WHILE_END_I:%.*]], label [[WHILE_COND_I]] ; CHECK: while.end.i: -; CHECK-NEXT: [[SUB_PTR_LHS_CAST_I:%.*]] = ptrtoint ptr [[TEST_0_I]] to i64 -; CHECK-NEXT: [[SUB_PTR_RHS_CAST_I:%.*]] = ptrtoint ptr [[VAL1]] to i64 -; CHECK-NEXT: [[SUB_PTR_SUB_I:%.*]] = sub i64 [[SUB_PTR_LHS_CAST_I]], [[SUB_PTR_RHS_CAST_I]] +; CHECK-NEXT: [[TMP1:%.*]] = icmp ne ptr [[TEST_0_I]], [[VAL1]] ; CHECK-NEXT: br label [[_Z3FOOPKC_EXIT]] ; CHECK: _Z3fooPKc.exit: -; CHECK-NEXT: [[RETVAL_0_I:%.*]] = phi i64 [ [[SUB_PTR_SUB_I]], [[WHILE_END_I]] ], [ 0, [[ENTRY]] ] +; CHECK-NEXT: [[RETVAL_0_I:%.*]] = phi i1 [ [[TMP1]], [[WHILE_END_I]] ], [ false, [[ENTRY]] ] ; CHECK-NEXT: [[CMP_I10:%.*]] = icmp eq ptr [[VAL2:%.*]], null ; CHECK-NEXT: br i1 [[CMP_I10]], label [[_Z3FOOPKC_EXIT20:%.*]], label [[WHILE_COND_I11:%.*]] ; CHECK: while.cond.i11: ; CHECK-NEXT: [[TEST_0_I12:%.*]] = phi ptr [ [[INCDEC_PTR_I14:%.*]], [[WHILE_COND_I11]] ], [ [[VAL2]], [[_Z3FOOPKC_EXIT]] ] -; CHECK-NEXT: [[TMP1:%.*]] = load i8, ptr [[TEST_0_I12]], align 1 -; CHECK-NEXT: [[CMP1_NOT_I13:%.*]] = icmp eq i8 [[TMP1]], 0 +; CHECK-NEXT: [[TMP2:%.*]] = load i8, ptr [[TEST_0_I12]], align 1 +; CHECK-NEXT: [[CMP1_NOT_I13:%.*]] = icmp eq i8 [[TMP2]], 0 ; CHECK-NEXT: [[INCDEC_PTR_I14]] = getelementptr inbounds i8, ptr [[TEST_0_I12]], i64 1 ; CHECK-NEXT: br i1 [[CMP1_NOT_I13]], label [[WHILE_END_I15:%.*]], label [[WHILE_COND_I11]] ; CHECK: while.end.i15: -; CHECK-NEXT: [[TMP2:%.*]] = icmp ne ptr [[TEST_0_I12]], [[VAL2]] +; CHECK-NEXT: [[TMP3:%.*]] = icmp ne ptr [[TEST_0_I12]], [[VAL2]] ; CHECK-NEXT: br label [[_Z3FOOPKC_EXIT20]] ; CHECK: _Z3fooPKc.exit20: -; CHECK-NEXT: [[RETVAL_0_I19:%.*]] = phi i1 [ [[TMP2]], [[WHILE_END_I15]] ], [ false, [[_Z3FOOPKC_EXIT]] ] -; CHECK-NEXT: [[TOBOOL:%.*]] = icmp ne i64 [[RETVAL_0_I]], 0 -; CHECK-NEXT: [[AND9:%.*]] = and i1 [[TOBOOL]], [[RETVAL_0_I19]] +; CHECK-NEXT: [[RETVAL_0_I19:%.*]] = phi i1 [ [[TMP3]], [[WHILE_END_I15]] ], [ false, [[_Z3FOOPKC_EXIT]] ] +; CHECK-NEXT: [[AND9:%.*]] = and i1 [[RETVAL_0_I]], [[RETVAL_0_I19]] ; CHECK-NEXT: ret i1 [[AND9]] ; entry: