Index: llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp =================================================================== --- llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -791,6 +791,12 @@ if (Known.isNegative()) return true; + if (const Operator *I = dyn_cast(Op)) { + if (I->getOpcode() == Instruction::Sub) + return isImpliedByDomCondition(ICmpInst::ICMP_SLT, I->getOperand(0), + I->getOperand(1), CxtI, DL); + } + return isImpliedByDomCondition( ICmpInst::ICMP_SLT, Op, Constant::getNullValue(Op->getType()), CxtI, DL); } Index: llvm/test/Transforms/InstCombine/abs-intrinsic.ll =================================================================== --- llvm/test/Transforms/InstCombine/abs-intrinsic.ll +++ llvm/test/Transforms/InstCombine/abs-intrinsic.ll @@ -424,3 +424,22 @@ %r = call i32 @llvm.abs.i32(i32 %s, i1 true) ret i32 %r } + +; Test from https://github.com/llvm/llvm-project/issues/54132. +define i32 @sub_abs(i32 %x, i32 %y) { +; CHECK-LABEL: @sub_abs +entry: + %cmp = icmp sgt i32 %x, %y + br i1 %cmp, label %cond.true, label %cond.end + +cond.true: + %sub = sub nsw i32 %x, %y +; CHECK-NOT: abs + %0 = tail call i32 @llvm.abs.i32(i32 %sub, i1 true) + %add = add nsw i32 %0, %y + br label %cond.end + +cond.end: + %cond = phi i32 [ %add, %cond.true ], [ 0, %entry ] + ret i32 %cond +} \ No newline at end of file