[llvm] [InstCombine] Fold (sub (xor X, (sext C)), (sext C)) => (select C (neg X), X) (PR #79417)
Kai Luo via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 25 23:52:32 PST 2024
================
@@ -0,0 +1,47 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
+; RUN: opt < %s -passes=instcombine -S | FileCheck %s
+
+define i64 @foo(i64 %a, i1 %b) {
+; CHECK-LABEL: define i64 @foo(
+; CHECK-SAME: i64 [[A:%.*]], i1 [[B:%.*]]) {
+; CHECK-NEXT: [[C:%.*]] = sext i1 [[B]] to i64
+; CHECK-NEXT: [[D:%.*]] = xor i64 [[C]], [[A]]
+; CHECK-NEXT: [[R:%.*]] = sub i64 [[D]], [[C]]
+; CHECK-NEXT: ret i64 [[R]]
+;
+ %c = sext i1 %b to i64
----------------
bzEq wrote:
It looks like `m_Xor` isn't commutative aware, so instcombine fails to catch the pattern.
`m_Xor` is implemented as
```
template <typename LHS, typename RHS>
inline BinaryOp_match<LHS, RHS, Instruction::Xor> m_Xor(const LHS &L,
const RHS &R) {
return BinaryOp_match<LHS, RHS, Instruction::Xor>(L, R);
}
```
Does anybody know why isn't `Commutable` set `true`?
https://github.com/llvm/llvm-project/pull/79417
More information about the llvm-commits
mailing list