Index: llvm/lib/IR/ConstantFold.cpp =================================================================== --- llvm/lib/IR/ConstantFold.cpp +++ llvm/lib/IR/ConstantFold.cpp @@ -2011,7 +2011,7 @@ } // icmp eq/ne(GV,null) -> false/true } else if (C2->isNullValue()) { - if (const GlobalValue *GV = dyn_cast(C1)) + if (const GlobalValue *GV = dyn_cast(C1)) { // Don't try to evaluate aliases. External weak GV can be null. if (!isa(GV) && !GV->hasExternalWeakLinkage() && !NullPointerIsDefined(nullptr /* F */, @@ -2021,6 +2021,16 @@ else if (pred == ICmpInst::ICMP_NE) return ConstantInt::getTrue(C1->getContext()); } + } + + // The caller is expected to commute the operands if the constant expression + // is C2. + // C1 >= 0 --> true + if (pred == ICmpInst::ICMP_UGE) + return Constant::getAllOnesValue(ResultTy); + // C1 < 0 --> false + if (pred == ICmpInst::ICMP_ULT) + return Constant::getNullValue(ResultTy); } // If the comparison is a comparison between two i1's, simplify it. Index: llvm/test/CodeGen/PowerPC/pr46923.ll =================================================================== --- llvm/test/CodeGen/PowerPC/pr46923.ll +++ llvm/test/CodeGen/PowerPC/pr46923.ll @@ -8,7 +8,6 @@ ; CHECK-LABEL: foo: ; CHECK: # %bb.0: # %entry ; CHECK-NEXT: li r3, 0 -; CHECK-NEXT: isel r3, 0, r3, 4*cr5+lt ; CHECK-NEXT: blr entry: br label %next Index: llvm/test/Transforms/InstCombine/vector_gep1-inseltpoison.ll =================================================================== --- llvm/test/Transforms/InstCombine/vector_gep1-inseltpoison.ll +++ llvm/test/Transforms/InstCombine/vector_gep1-inseltpoison.ll @@ -64,7 +64,7 @@ define @test8() { ; CHECK-LABEL: @test8( -; CHECK-NEXT: ret icmp ult ( zext ( shufflevector ( insertelement ( poison, i32 1, i32 0), poison, zeroinitializer) to ), zeroinitializer) +; CHECK-NEXT: ret zeroinitializer ; %ins = insertelement poison, i32 1, i32 0 %b = shufflevector %ins, poison, zeroinitializer Index: llvm/test/Transforms/InstCombine/vector_gep1.ll =================================================================== --- llvm/test/Transforms/InstCombine/vector_gep1.ll +++ llvm/test/Transforms/InstCombine/vector_gep1.ll @@ -64,7 +64,7 @@ define @test8() { ; CHECK-LABEL: @test8( -; CHECK-NEXT: ret icmp ult ( zext ( shufflevector ( insertelement ( undef, i32 1, i32 0), undef, zeroinitializer) to ), zeroinitializer) +; CHECK-NEXT: ret zeroinitializer ; %ins = insertelement undef, i32 1, i32 0 %b = shufflevector %ins, undef, zeroinitializer Index: llvm/test/Transforms/InstSimplify/ConstProp/icmp-null.ll =================================================================== --- llvm/test/Transforms/InstSimplify/ConstProp/icmp-null.ll +++ llvm/test/Transforms/InstSimplify/ConstProp/icmp-null.ll @@ -3,7 +3,7 @@ define i1 @ule_null_constexpr(i8* %x) { ; CHECK-LABEL: @ule_null_constexpr( -; CHECK-NEXT: ret i1 icmp uge (i8 (...)* bitcast (i1 (i8*)* @ule_null_constexpr to i8 (...)*), i8 (...)* null) +; CHECK-NEXT: ret i1 true ; %cmp = icmp ule i8 (...)* null, bitcast (i1 (i8*)* @ule_null_constexpr to i8 (...)*) ret i1 %cmp @@ -11,7 +11,7 @@ define i1 @ugt_null_constexpr(i8* %x) { ; CHECK-LABEL: @ugt_null_constexpr( -; CHECK-NEXT: ret i1 icmp ult (i8 (...)* bitcast (i1 (i8*)* @ugt_null_constexpr to i8 (...)*), i8 (...)* null) +; CHECK-NEXT: ret i1 false ; %cmp = icmp ugt i8 (...)* null, bitcast (i1 (i8*)* @ugt_null_constexpr to i8 (...)*) ret i1 %cmp @@ -19,7 +19,7 @@ define i1 @uge_constexpr_null(i8* %x) { ; CHECK-LABEL: @uge_constexpr_null( -; CHECK-NEXT: ret i1 icmp uge (i8 (...)* bitcast (i1 (i8*)* @ugt_null_constexpr to i8 (...)*), i8 (...)* null) +; CHECK-NEXT: ret i1 true ; %cmp = icmp uge i8 (...)* bitcast (i1 (i8*)* @ugt_null_constexpr to i8 (...)*), null ret i1 %cmp @@ -27,7 +27,7 @@ define i1 @ult_constexpr_null(i8* %x) { ; CHECK-LABEL: @ult_constexpr_null( -; CHECK-NEXT: ret i1 icmp ult (i8 (...)* bitcast (i1 (i8*)* @ugt_null_constexpr to i8 (...)*), i8 (...)* null) +; CHECK-NEXT: ret i1 false ; %cmp = icmp ult i8 (...)* bitcast (i1 (i8*)* @ugt_null_constexpr to i8 (...)*), null ret i1 %cmp Index: llvm/test/Transforms/JumpThreading/thread-two-bbs.ll =================================================================== --- llvm/test/Transforms/JumpThreading/thread-two-bbs.ll +++ llvm/test/Transforms/JumpThreading/thread-two-bbs.ll @@ -112,7 +112,7 @@ ; as "true", causing jump threading to a wrong destination. define void @foo3(i8* %arg1, i8* %arg2) { ; CHECK-LABEL: @foo -; CHECK-NOT: bb_{{[^ ]*}}.thread: +; CHECK: bb_{{[^ ]*}}.thread: entry: %cmp1 = icmp eq i8* %arg1, null br i1 %cmp1, label %bb_bar1, label %bb_end