[llvm] [ValueTracking] Improve `isImpliedCondCommonOperandWithConstants` to handle truncated LHS (PR #69829)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 22 00:45:32 PDT 2023
================
@@ -8272,8 +8288,19 @@ static std::optional<bool> isImpliedCondICmps(const ICmpInst *LHS,
// Can we infer anything when the 0-operands match and the 1-operands are
// constants (not necessarily matching)?
const APInt *LC, *RC;
- if (L0 == R0 && match(L1, m_APInt(LC)) && match(R1, m_APInt(RC)))
- return isImpliedCondCommonOperandWithConstants(LPred, *LC, RPred, *RC);
+ if (match(L1, m_APInt(LC)) && match(R1, m_APInt(RC))) {
+ if (auto Res = isImpliedCondCommonOperandWithConstants(L0, LPred, *LC, R0,
+ RPred, *RC))
+ return Res;
+
+ if (match(L0, m_Trunc(m_Specific(R0)))) {
----------------
dtcxzyw wrote:
No. We need the law of excluded middle to cover more cases.
Example:
```
define i1 @g(i32 %a) {
; CHECK-LABEL: define i1 @g(
; CHECK-SAME: i32 [[A:%.*]]) {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[B:%.*]] = trunc i32 [[A]] to i16
; CHECK-NEXT: [[CMP2:%.*]] = icmp sgt i16 [[B]], 2
; CHECK-NEXT: ret i1 [[CMP2]]
;
entry:
%cmp = icmp eq i32 %a, 3
%b = trunc i32 %a to i16
%cmp2 = icmp sgt i16 %b, 2
%or9 = or i1 %cmp, %cmp2
ret i1 %or9
}
```
https://github.com/llvm/llvm-project/pull/69829
More information about the llvm-commits
mailing list