[llvm] [ValueTracking] Improve `isImpliedCondCommonOperandWithConstants` to handle truncated LHS (PR #69829)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 4 11:37:49 PDT 2023
================
@@ -0,0 +1,70 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 3
+; RUN: opt < %s -passes=instcombine -S | FileCheck %s
+
+; Tests from PR68514
+define i1 @f(i32 %a) {
+; CHECK-LABEL: define i1 @f(
+; CHECK-SAME: i32 [[A:%.*]]) {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: ret i1 false
+;
+entry:
+ %cmp = icmp eq i32 %a, 0
+ %b = trunc i32 %a to i16
+ %cmp2 = icmp sgt i16 %b, 2
+ %and9 = and i1 %cmp, %cmp2
+ ret i1 %and9
+}
+
+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
+}
+
+; b = trunc(a)
+
+define i1 @fold_trunc(i32 %a) {
+; CHECK-LABEL: define i1 @fold_trunc(
+; CHECK-SAME: i32 [[A:%.*]]) {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32 [[A]], 2
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+entry:
+ %cmp = icmp ugt i32 %a, 2
+ %b = trunc i32 %a to i16
+ %cmp2 = icmp ugt i16 %b, 2
+ %and9 = or i1 %cmp, %cmp2
+ ret i1 %and9
+}
+
+; Negative tests
+
+define i1 @nofold_trunc(i32 %a) {
+; CHECK-LABEL: define i1 @nofold_trunc(
+; CHECK-SAME: i32 [[A:%.*]]) {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32 [[A]], 3
+; CHECK-NEXT: [[B:%.*]] = trunc i32 [[A]] to i16
+; CHECK-NEXT: [[CMP2:%.*]] = icmp ugt i16 [[B]], 2
+; CHECK-NEXT: [[AND9:%.*]] = or i1 [[CMP]], [[CMP2]]
+; CHECK-NEXT: ret i1 [[AND9]]
+;
+entry:
+ %cmp = icmp ugt i32 %a, 3
+ %b = trunc i32 %a to i16
+ %cmp2 = icmp ugt i16 %b, 2
+ %and9 = or i1 %cmp, %cmp2
+ ret i1 %and9
----------------
goldsteinn wrote:
Missing test for `lhs = trunc(rhs)`
https://github.com/llvm/llvm-project/pull/69829
More information about the llvm-commits
mailing list