[Mlir-commits] [mlir] [mlir][AMDGPU] Add better load/store lowering for full select mask (PR #146748)
Kunwar Grover
llvmlistbot at llvm.org
Thu Jul 10 04:26:25 PDT 2025
================
@@ -61,6 +61,36 @@ static Value createVectorLoadForMaskedLoad(OpBuilder &builder, Location loc,
return res;
}
+/// Check if the given value comes from a:
+///
+/// arith.select %cond, TRUE/FALSE, TRUE/FALSE
+///
+/// i.e the condition is either always true or it's always false.
+///
+/// Returns the condition to use for scf.if (condition) { true } else { false }.
+static FailureOr<Value> matchFullSelect(OpBuilder &b, Value val) {
+ auto selectOp = val.getDefiningOp<arith::SelectOp>();
+ if (!selectOp)
+ return failure();
+ std::optional<int64_t> trueInt = getConstantIntValue(selectOp.getTrueValue());
+ std::optional<int64_t> falseInt =
+ getConstantIntValue(selectOp.getFalseValue());
+ if (!trueInt || !falseInt)
+ return failure();
+ // getConstantIntValue returns -1 for "true" for bools.
+ if (trueInt.value() == -1 && falseInt.value() == 0)
+ return selectOp.getCondition();
+
+ if (trueInt.value() == 0 && falseInt.value() == -1) {
+ Value cond = selectOp.getCondition();
+ Value one = b.create<arith::ConstantIntOp>(cond.getLoc(), /*value=*/true,
+ /*width=*/1);
+ Value inverse = b.create<arith::XOrIOp>(cond.getLoc(), cond, one);
+ return inverse;
+ }
+ return failure();
----------------
Groverkss wrote:
not needed anymore
https://github.com/llvm/llvm-project/pull/146748
More information about the Mlir-commits
mailing list