[llvm] [InstCombine] Handle trunc i1 pattern in eq-of-parts fold (PR #112704)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 17 18:16:24 PDT 2024
================
@@ -3538,6 +3546,9 @@ Value *InstCombinerImpl::foldBooleanAndOr(Value *LHS, Value *RHS,
if (Value *Res = foldLogicOfFCmps(LHSCmp, RHSCmp, IsAnd, IsLogical))
return Res;
+ if (Value *Res = foldEqOfParts(LHS, RHS, IsAnd))
----------------
dtcxzyw wrote:
Regression:
```
define i1 @jv_identical(i64 %0, i64 %2) {
%.sroa.08.0.extract.trunc = trunc i64 %0 to i8
%.sroa.311.0.extract.shift = lshr i64 %0, 16
%.sroa.311.0.extract.trunc = trunc i64 %.sroa.311.0.extract.shift to i16
%.sroa.0.0.extract.trunc = trunc i64 %2 to i8
%.sroa.37.0.extract.shift = lshr i64 %2, 16
%.sroa.37.0.extract.trunc = trunc i64 %.sroa.37.0.extract.shift to i16
%.not = icmp eq i8 %.sroa.08.0.extract.trunc, %.sroa.0.0.extract.trunc
%.not2 = icmp eq i16 %.sroa.311.0.extract.trunc, %.sroa.37.0.extract.trunc
%or.cond = and i1 %.not, %.not2
%.not3.unshifted = xor i64 %2, %0
%.not3 = icmp ult i64 %.not3.unshifted, 4294967296
%or.cond15 = and i1 %.not3, %or.cond
ret i1 %or.cond15
}
```
Before:
```
define i1 @jv_identical(i64 %0, i64 %1) {
%.sroa.08.0.extract.trunc = trunc i64 %0 to i8
%.sroa.311.0.extract.shift = lshr i64 %0, 16
%.sroa.311.0.extract.trunc = trunc i64 %.sroa.311.0.extract.shift to i16
%.sroa.0.0.extract.trunc = trunc i64 %1 to i8
%.sroa.37.0.extract.shift = lshr i64 %1, 16
%.sroa.37.0.extract.trunc = trunc i64 %.sroa.37.0.extract.shift to i16
%.not = icmp eq i8 %.sroa.08.0.extract.trunc, %.sroa.0.0.extract.trunc
%.not2 = icmp eq i16 %.sroa.311.0.extract.trunc, %.sroa.37.0.extract.trunc
%or.cond = and i1 %.not, %.not2
%.not3.unshifted = xor i64 %1, %0
%.not3 = icmp ult i64 %.not3.unshifted, 4294967296
%or.cond15 = and i1 %.not3, %or.cond
ret i1 %or.cond15
}
```
After:
```
define i1 @jv_identical(i64 %0, i64 %1) {
%.sroa.08.0.extract.trunc = trunc i64 %0 to i8
%.sroa.0.0.extract.trunc = trunc i64 %1 to i8
%.not = icmp eq i8 %.sroa.08.0.extract.trunc, %.sroa.0.0.extract.trunc
%.unshifted = xor i64 %1, %0
%3 = icmp ult i64 %.unshifted, 65536
%or.cond15 = and i1 %.not, %3
ret i1 %or.cond15
}
```
I think this fold should be moved before https://github.com/llvm/llvm-project/blob/e9eec14bb3566f6578950797559de98678f16985/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp#L3446-L3448
https://github.com/llvm/llvm-project/pull/112704
More information about the llvm-commits
mailing list