Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/enzyme_ad/jax/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -987,10 +987,10 @@ NonNegativeResultAnalysis::State NonNegativeResultAnalysis::localGuaranteed(

// (mul a a) is always non-negative
if (auto mulOp = dyn_cast<stablehlo::MulOp>(op)) {
auto lhsOp = mulOp.getLhs().getDefiningOp();
auto rhsOp = mulOp.getRhs().getDefiningOp();

if (lhsOp == rhsOp) {
// Compare the operand Values, not their defining ops: two distinct block
// arguments both have a null defining op, so a defining-op comparison
// would wrongly prove mul(%arg0, %arg1) non-negative.
if (mulOp.getLhs() == mulOp.getRhs()) {
return State::GUARANTEED;
}
}
Expand Down
9 changes: 9 additions & 0 deletions test/lit_tests/abspositive.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,12 @@ func.func @test8(%arg0: tensor<4xf64>) -> tensor<4xf64> {
// CHECK-NEXT: %0 = stablehlo.logistic %arg0 {enzymexla.non_negative = [#enzymexla<guaranteed GUARANTEED>]} : tensor<4xf64>
// CHECK-NEXT: return %0 : tensor<4xf64>
// CHECK-NEXT: }

// mul of two distinct block args must NOT be proven non-negative: the product
// is negative whenever the args have opposite signs, so the abs has to stay.
func.func @test9(%arg0: tensor<12xf64>, %arg1: tensor<12xf64>) -> tensor<12xf64> {
%0 = stablehlo.multiply %arg0, %arg1 : tensor<12xf64>
// CHECK: stablehlo.abs
%1 = stablehlo.abs %0 : tensor<12xf64>
return %1 : tensor<12xf64>
}
Loading