[MLIR][Arith] SelectOp fix invalid folding (#117555)
The pattern `select %x, true, false => %x` is only valid in case that the return type is identical to the type of `%x` (i.e., i1). Hence, the check `isInteger(1)` was replaced with `isSignlessInteger(1)`. Fixes: https://github.com/llvm/llvm-project/issues/117554
This commit is contained in:
parent
59b3630e03
commit
619e4b7154
@ -2322,7 +2322,8 @@ OpFoldResult arith::SelectOp::fold(FoldAdaptor adaptor) {
|
||||
return trueVal;
|
||||
|
||||
// select %x, true, false => %x
|
||||
if (getType().isInteger(1) && matchPattern(adaptor.getTrueValue(), m_One()) &&
|
||||
if (getType().isSignlessInteger(1) &&
|
||||
matchPattern(adaptor.getTrueValue(), m_One()) &&
|
||||
matchPattern(adaptor.getFalseValue(), m_Zero()))
|
||||
return condition;
|
||||
|
||||
|
@ -54,6 +54,18 @@ func.func @select_extui_i1(%arg0: i1) -> i1 {
|
||||
return %res : i1
|
||||
}
|
||||
|
||||
// CHECK-LABEL: @select_no_fold_ui1
|
||||
// CHECK: %[[CONST_0:.+]] = "test.constant"() <{value = 0 : i32}> : () -> ui1
|
||||
// CHECK: %[[CONST_1:.+]] = "test.constant"() <{value = 1 : i32}> : () -> ui1
|
||||
// CHECK-NEXT: %[[RES:.+]] = arith.select %arg0, %[[CONST_1]], %[[CONST_0]] : ui1
|
||||
// CHECK-NEXT: return %[[RES]]
|
||||
func.func @select_no_fold_ui1(%arg0: i1) -> ui1 {
|
||||
%c0_i1 = "test.constant"() {value = 0 : i32} : () -> ui1
|
||||
%c1_i1 = "test.constant"() {value = 1 : i32} : () -> ui1
|
||||
%res = arith.select %arg0, %c1_i1, %c0_i1 : ui1
|
||||
return %res : ui1
|
||||
}
|
||||
|
||||
// CHECK-LABEL: @select_cst_false_scalar
|
||||
// CHECK-SAME: (%[[ARG0:.+]]: i32, %[[ARG1:.+]]: i32)
|
||||
// CHECK-NEXT: return %[[ARG1]]
|
||||
|
Loading…
x
Reference in New Issue
Block a user