[llvm] [InstSimplify] Simplify select if it combinated `and/or/xor` (PR #73362)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 8 06:17:31 PST 2024
================
@@ -4640,6 +4692,9 @@ static Value *simplifySelectWithICmpCond(Value *CondVal, Value *TrueVal,
}
}
+ if (Value *V = simplifySelectBitTestSpec(CmpLHS, CmpRHS, TrueVal, FalseVal))
----------------
dtcxzyw wrote:
You should implement this logic in `simplifySelectWithICmpEq` (rebasing may be required).
Please add a negative test:
```
define i32 @src_select_and_eq0_or_xor(i32 %x, i32 %y) {
; CHECK-LABEL: @src_select_and_eq0_or_xor(
; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: ret i32 [[XOR]]
;
%and = and i32 %x, %y
%and0 = icmp slt i32 %and, 0
%xor = xor i32 %x, %y
%or = or i32 %x, %y
%cond = select i1 %and0, i32 %or, i32 %xor
ret i32 %cond
}
```
Handling `ICMP_NE` is unnecessary because we always canonicalize `A != 0 ? C : D` into `A == 0 ? D : C`. See the code above this line:
https://github.com/llvm/llvm-project/blob/2bf01d73f6ebca11f36c17a65b7a86109d44681e/llvm/lib/Analysis/InstructionSimplify.cpp#L4620-L4624
https://github.com/llvm/llvm-project/pull/73362
More information about the llvm-commits
mailing list