[clang] [llvm] [ValueTracking] Convert `isKnownNonZero` to use SimplifyQuery (PR #85863)
https://github.com/dtcxzyw updated https://github.com/llvm/llvm-project/pull/85863 >From bacdc24af088560a986028824a0ac43e929c2f1b Mon Sep 17 00:00:00 2001 From: Yingwei Zheng Date: Thu, 21 Mar 2024 21:10:46 +0800 Subject: [PATCH 1/2] [ValueTracking] Add pre-commit tests. NFC. --- llvm/test/Transforms/InstCombine/icmp-dom.ll | 139 +++ 1 file changed, 139 insertions(+) diff --git a/llvm/test/Transforms/InstCombine/icmp-dom.ll b/llvm/test/Transforms/InstCombine/icmp-dom.ll index f4b9022d14349b..138254d912b259 100644 --- a/llvm/test/Transforms/InstCombine/icmp-dom.ll +++ b/llvm/test/Transforms/InstCombine/icmp-dom.ll @@ -403,3 +403,142 @@ truelabel: falselabel: ret i8 0 } + +define i1 @and_mask1_eq(i32 %conv) { +; CHECK-LABEL: @and_mask1_eq( +; CHECK-NEXT: entry: +; CHECK-NEXT:[[AND:%.*]] = and i32 [[CONV:%.*]], 1 +; CHECK-NEXT:[[CMP:%.*]] = icmp eq i32 [[AND]], 0 +; CHECK-NEXT:br i1 [[CMP]], label [[THEN:%.*]], label [[ELSE:%.*]] +; CHECK: then: +; CHECK-NEXT:ret i1 false +; CHECK: else: +; CHECK-NEXT:[[AND1:%.*]] = and i32 [[CONV]], 3 +; CHECK-NEXT:[[CMP1:%.*]] = icmp eq i32 [[AND1]], 0 +; CHECK-NEXT:ret i1 [[CMP1]] +; +entry: + %and = and i32 %conv, 1 + %cmp = icmp eq i32 %and, 0 + br i1 %cmp, label %then, label %else + +then: + ret i1 0 + +else: + %and1 = and i32 %conv, 3 + %cmp1 = icmp eq i32 %and1, 0 + ret i1 %cmp1 +} + +define i1 @and_mask1_ne(i32 %conv) { +; CHECK-LABEL: @and_mask1_ne( +; CHECK-NEXT: entry: +; CHECK-NEXT:[[AND:%.*]] = and i32 [[CONV:%.*]], 1 +; CHECK-NEXT:[[CMP:%.*]] = icmp eq i32 [[AND]], 0 +; CHECK-NEXT:br i1 [[CMP]], label [[THEN:%.*]], label [[ELSE:%.*]] +; CHECK: then: +; CHECK-NEXT:ret i1 false +; CHECK: else: +; CHECK-NEXT:[[AND1:%.*]] = and i32 [[CONV]], 3 +; CHECK-NEXT:[[CMP1:%.*]] = icmp ne i32 [[AND1]], 0 +; CHECK-NEXT:ret i1 [[CMP1]] +; +entry: + %and = and i32 %conv, 1 + %cmp = icmp eq i32 %and, 0 + br i1 %cmp, label %then, label %else + +then: + ret i1 0 + +else: + %and1 = and i32 %conv, 3 + %cmp1 = icmp ne i32 %and1, 0 + ret i1 %cmp1 +} + +define i1 @and_mask2(i32 %conv) { +; CHECK-LABEL: @and_mask2( +; CHECK-NEXT: entry: +; CHECK-NEXT:[[AND:%.*]] = and i32 [[CONV:%.*]], 4 +; CHECK-NEXT:[[CMP:%.*]] = icmp eq i32 [[AND]], 0 +; CHECK-NEXT:br i1 [[CMP]], label [[THEN:%.*]], label [[ELSE:%.*]] +; CHECK: then: +; CHECK-NEXT:ret i1 false +; CHECK: else: +; CHECK-NEXT:[[AND1:%.*]] = and i32 [[CONV]], 3 +; CHECK-NEXT:[[CMP1:%.*]] = icmp eq i32 [[AND1]], 0 +; CHECK-NEXT:ret i1 [[CMP1]] +; +entry: + %and = and i32 %conv, 4 + %cmp = icmp eq i32 %and, 0 + br i1 %cmp, label %then, label %else + +then: + ret i1 0 + +else: + %and1 = and i32 %conv, 3 + %cmp1 = icmp eq i32 %and1, 0 + ret i1 %cmp1 +} + +; TODO: %cmp1 can be folded into false. + +define i1 @and_mask3(i32 %conv) { +; CHECK-LABEL: @and_mask3( +; CHECK-NEXT: entry: +; CHECK-NEXT:[[AND:%.*]] = and i32 [[CONV:%.*]], 3 +; CHECK-NEXT:[[CMP:%.*]] = icmp eq i32 [[AND]], 0 +; CHECK-NEXT:br i1 [[CMP]], label [[THEN:%.*]], label [[ELSE:%.*]] +; CHECK: then: +; CHECK-NEXT:ret i1 false +; CHECK: else: +; CHECK-NEXT:[[AND1:%.*]] = and i32 [[CONV]], 7 +; CHECK-NEXT:[[CMP1:%.*]] = icmp eq i32 [[AND1]], 0 +; CHECK-NEXT:ret i1 [[CMP1]] +; +entry: + %and = and i32 %conv, 3 + %cmp = icmp eq i32 %and, 0 + br i1 %cmp, label %then, label %else + +then: + ret i1 0 + +else: + %and1 = and i32 %conv, 7 + %cmp1 = icmp eq i32 %and1, 0 + ret i1 %cmp1 +} + +; TODO: %cmp1 can be folded into false. + +define i1 @and_mask4(i32 %conv) { +; CHECK-LABEL: @and_mask4( +; CHECK-NEXT: entry: +; CHECK-NEXT:[[AND:%.*]] = and i32 [[CONV:%.*]], 4 +; CHECK-NEXT:[[CMP:%.*]] = icmp eq i32 [[AND]], 0 +; CHECK-NEXT:br i1 [[CMP]], label [[THEN:%.*]], label [[ELSE:%.*]] +; CHECK: then: +; CHECK-NEXT:ret i1 false +; CHECK: else: +; CHECK-NEXT:[[AND1:%.*]] = and i32 [[CONV]], 7 +; CHECK-NEXT:[[CMP1:%.*]] = icmp eq i32 [[AND1]], 0 +; CHECK-NEXT:ret i1 [[CMP1]] +; +entry: + %and = and i32 %conv, 4 + %cmp = icmp eq i32 %and, 0 + br i1 %cmp, label %then, label %else + +then: + ret i1 0 + +else: + %and1 = and i32 %conv, 7 + %cmp1 = icmp eq i32 %and1, 0 + ret i1 %cmp1 +} >From 746f3cc306d2cddb222904e73157daf29114a3f3 Mon Sep 17 00:00:00 2001 From: Yingwei Zheng Date: Thu, 21 Mar 2024 21:21:13 +0800 Subject: [PATCH 2/2] [ValueTracking] Convert `isKnownNonZero` to use SimplifyQuery --- clang/lib/CodeGen/CGCall.cpp | 4 +-- llvm/include/llvm/Analysis/ValueTracking.h| 6 +--- llvm/lib/Analysis/BasicAliasAnalysis.cpp | 3 +- llvm/lib/Analysis/InstructionSimplify.cpp | 29 --- llvm/lib/Analysis/LazyValueInfo.cpp | 5 ++-- llvm/lib/Analysis/Loads.cpp | 6 ++-- llvm/lib/Analysis/ScalarEvolution.cpp | 2 +- llvm/lib/Analysis/ValueTrack
[clang] [llvm] [ValueTracking] Convert `isKnownNonZero` to use SimplifyQuery (PR #85863)
dtcxzyw wrote: > Can you please fix the clang build? Done. https://github.com/llvm/llvm-project/pull/85863 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ValueTracking] Convert `isKnownNonZero` to use SimplifyQuery (PR #85863)
https://github.com/dtcxzyw updated https://github.com/llvm/llvm-project/pull/85863 >From 9b725ffdb93b3029263129063d021063783f9cd9 Mon Sep 17 00:00:00 2001 From: Yingwei Zheng Date: Thu, 21 Mar 2024 21:10:46 +0800 Subject: [PATCH 1/4] [ValueTracking] Add pre-commit tests. NFC. --- llvm/test/Transforms/InstCombine/icmp-dom.ll | 139 +++ 1 file changed, 139 insertions(+) diff --git a/llvm/test/Transforms/InstCombine/icmp-dom.ll b/llvm/test/Transforms/InstCombine/icmp-dom.ll index f4b9022d14349b2..138254d912b259b 100644 --- a/llvm/test/Transforms/InstCombine/icmp-dom.ll +++ b/llvm/test/Transforms/InstCombine/icmp-dom.ll @@ -403,3 +403,142 @@ truelabel: falselabel: ret i8 0 } + +define i1 @and_mask1_eq(i32 %conv) { +; CHECK-LABEL: @and_mask1_eq( +; CHECK-NEXT: entry: +; CHECK-NEXT:[[AND:%.*]] = and i32 [[CONV:%.*]], 1 +; CHECK-NEXT:[[CMP:%.*]] = icmp eq i32 [[AND]], 0 +; CHECK-NEXT:br i1 [[CMP]], label [[THEN:%.*]], label [[ELSE:%.*]] +; CHECK: then: +; CHECK-NEXT:ret i1 false +; CHECK: else: +; CHECK-NEXT:[[AND1:%.*]] = and i32 [[CONV]], 3 +; CHECK-NEXT:[[CMP1:%.*]] = icmp eq i32 [[AND1]], 0 +; CHECK-NEXT:ret i1 [[CMP1]] +; +entry: + %and = and i32 %conv, 1 + %cmp = icmp eq i32 %and, 0 + br i1 %cmp, label %then, label %else + +then: + ret i1 0 + +else: + %and1 = and i32 %conv, 3 + %cmp1 = icmp eq i32 %and1, 0 + ret i1 %cmp1 +} + +define i1 @and_mask1_ne(i32 %conv) { +; CHECK-LABEL: @and_mask1_ne( +; CHECK-NEXT: entry: +; CHECK-NEXT:[[AND:%.*]] = and i32 [[CONV:%.*]], 1 +; CHECK-NEXT:[[CMP:%.*]] = icmp eq i32 [[AND]], 0 +; CHECK-NEXT:br i1 [[CMP]], label [[THEN:%.*]], label [[ELSE:%.*]] +; CHECK: then: +; CHECK-NEXT:ret i1 false +; CHECK: else: +; CHECK-NEXT:[[AND1:%.*]] = and i32 [[CONV]], 3 +; CHECK-NEXT:[[CMP1:%.*]] = icmp ne i32 [[AND1]], 0 +; CHECK-NEXT:ret i1 [[CMP1]] +; +entry: + %and = and i32 %conv, 1 + %cmp = icmp eq i32 %and, 0 + br i1 %cmp, label %then, label %else + +then: + ret i1 0 + +else: + %and1 = and i32 %conv, 3 + %cmp1 = icmp ne i32 %and1, 0 + ret i1 %cmp1 +} + +define i1 @and_mask2(i32 %conv) { +; CHECK-LABEL: @and_mask2( +; CHECK-NEXT: entry: +; CHECK-NEXT:[[AND:%.*]] = and i32 [[CONV:%.*]], 4 +; CHECK-NEXT:[[CMP:%.*]] = icmp eq i32 [[AND]], 0 +; CHECK-NEXT:br i1 [[CMP]], label [[THEN:%.*]], label [[ELSE:%.*]] +; CHECK: then: +; CHECK-NEXT:ret i1 false +; CHECK: else: +; CHECK-NEXT:[[AND1:%.*]] = and i32 [[CONV]], 3 +; CHECK-NEXT:[[CMP1:%.*]] = icmp eq i32 [[AND1]], 0 +; CHECK-NEXT:ret i1 [[CMP1]] +; +entry: + %and = and i32 %conv, 4 + %cmp = icmp eq i32 %and, 0 + br i1 %cmp, label %then, label %else + +then: + ret i1 0 + +else: + %and1 = and i32 %conv, 3 + %cmp1 = icmp eq i32 %and1, 0 + ret i1 %cmp1 +} + +; TODO: %cmp1 can be folded into false. + +define i1 @and_mask3(i32 %conv) { +; CHECK-LABEL: @and_mask3( +; CHECK-NEXT: entry: +; CHECK-NEXT:[[AND:%.*]] = and i32 [[CONV:%.*]], 3 +; CHECK-NEXT:[[CMP:%.*]] = icmp eq i32 [[AND]], 0 +; CHECK-NEXT:br i1 [[CMP]], label [[THEN:%.*]], label [[ELSE:%.*]] +; CHECK: then: +; CHECK-NEXT:ret i1 false +; CHECK: else: +; CHECK-NEXT:[[AND1:%.*]] = and i32 [[CONV]], 7 +; CHECK-NEXT:[[CMP1:%.*]] = icmp eq i32 [[AND1]], 0 +; CHECK-NEXT:ret i1 [[CMP1]] +; +entry: + %and = and i32 %conv, 3 + %cmp = icmp eq i32 %and, 0 + br i1 %cmp, label %then, label %else + +then: + ret i1 0 + +else: + %and1 = and i32 %conv, 7 + %cmp1 = icmp eq i32 %and1, 0 + ret i1 %cmp1 +} + +; TODO: %cmp1 can be folded into false. + +define i1 @and_mask4(i32 %conv) { +; CHECK-LABEL: @and_mask4( +; CHECK-NEXT: entry: +; CHECK-NEXT:[[AND:%.*]] = and i32 [[CONV:%.*]], 4 +; CHECK-NEXT:[[CMP:%.*]] = icmp eq i32 [[AND]], 0 +; CHECK-NEXT:br i1 [[CMP]], label [[THEN:%.*]], label [[ELSE:%.*]] +; CHECK: then: +; CHECK-NEXT:ret i1 false +; CHECK: else: +; CHECK-NEXT:[[AND1:%.*]] = and i32 [[CONV]], 7 +; CHECK-NEXT:[[CMP1:%.*]] = icmp eq i32 [[AND1]], 0 +; CHECK-NEXT:ret i1 [[CMP1]] +; +entry: + %and = and i32 %conv, 4 + %cmp = icmp eq i32 %and, 0 + br i1 %cmp, label %then, label %else + +then: + ret i1 0 + +else: + %and1 = and i32 %conv, 7 + %cmp1 = icmp eq i32 %and1, 0 + ret i1 %cmp1 +} >From b80b7de04dcad4be5eff5545ee0a67984c55f17e Mon Sep 17 00:00:00 2001 From: Yingwei Zheng Date: Thu, 21 Mar 2024 21:21:13 +0800 Subject: [PATCH 2/4] [ValueTracking] Convert `isKnownNonZero` to use SimplifyQuery --- llvm/include/llvm/Analysis/ValueTracking.h| 6 +--- llvm/lib/Analysis/BasicAliasAnalysis.cpp | 3 +- llvm/lib/Analysis/InstructionSimplify.cpp | 29 --- llvm/lib/Analysis/LazyValueInfo.cpp | 5 ++-- llvm/lib/Analysis/Loads.cpp | 6 ++-- llvm/lib/Analysis/ScalarEvolution.cpp | 2 +- llvm/lib/Analysis/ValueTracking.cpp | 17 +++ llvm/lib/CodeGen/C
[clang] [llvm] [ValueTracking] Convert `isKnownNonZero` to use SimplifyQuery (PR #85863)
dtcxzyw wrote: > Looks like the clang build is failing again? Done. https://github.com/llvm/llvm-project/pull/85863 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ValueTracking] Convert `isKnownNonZero` to use SimplifyQuery (PR #85863)
https://github.com/nikic approved this pull request. LG https://github.com/llvm/llvm-project/pull/85863 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ValueTracking] Convert `isKnownNonZero` to use SimplifyQuery (PR #85863)
https://github.com/dtcxzyw closed https://github.com/llvm/llvm-project/pull/85863 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ValueTracking] Convert `isKnownNonZero` to use SimplifyQuery (PR #85863)
@@ -645,7 +645,7 @@ LazyValueInfoImpl::solveBlockValueImpl(Value *Val, BasicBlock *BB) { // instruction is placed, even if it could legally be hoisted much higher. // That is unfortunate. PointerType *PT = dyn_cast(BBI->getType()); - if (PT && isKnownNonZero(BBI, DL)) + if (PT && isKnownNonZero(BBI, /*Depth=*/0, DL)) hvdijk wrote: The fact that this PR changes it so that `isKnownNonZero(BBI, DL)` is valid in LLVM 18, used to be valid in LLVM 19, is currently an error in LLVM 19, but will become valid in LLVM 19 again is unfortunate and difficult to account for in downstream projects. @goldsteinn If you are going to change that, do you think it is worth updating downstream code to support the current API, or is that change going to go in fast enough that we can just wait? https://github.com/llvm/llvm-project/pull/85863 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ValueTracking] Convert `isKnownNonZero` to use SimplifyQuery (PR #85863)
@@ -645,7 +645,7 @@ LazyValueInfoImpl::solveBlockValueImpl(Value *Val, BasicBlock *BB) { // instruction is placed, even if it could legally be hoisted much higher. // That is unfortunate. PointerType *PT = dyn_cast(BBI->getType()); - if (PT && isKnownNonZero(BBI, DL)) + if (PT && isKnownNonZero(BBI, /*Depth=*/0, DL)) goldsteinn wrote: If I don't make the llvm19 cutoff, I'll drop it. https://github.com/llvm/llvm-project/pull/85863 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ValueTracking] Convert `isKnownNonZero` to use SimplifyQuery (PR #85863)
@@ -645,7 +645,7 @@ LazyValueInfoImpl::solveBlockValueImpl(Value *Val, BasicBlock *BB) { // instruction is placed, even if it could legally be hoisted much higher. // That is unfortunate. PointerType *PT = dyn_cast(BBI->getType()); - if (PT && isKnownNonZero(BBI, DL)) + if (PT && isKnownNonZero(BBI, /*Depth=*/0, DL)) hvdijk wrote: Thanks, I had been slightly optimistic that this was just going to be a few days, but it sounds like it's going to be longer. In that case I will check what is easiest for us (which might be to submit that LLVM change ourselves). https://github.com/llvm/llvm-project/pull/85863 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ValueTracking] Convert `isKnownNonZero` to use SimplifyQuery (PR #85863)
@@ -645,7 +645,7 @@ LazyValueInfoImpl::solveBlockValueImpl(Value *Val, BasicBlock *BB) { // instruction is placed, even if it could legally be hoisted much higher. // That is unfortunate. PointerType *PT = dyn_cast(BBI->getType()); - if (PT && isKnownNonZero(BBI, DL)) + if (PT && isKnownNonZero(BBI, /*Depth=*/0, DL)) hvdijk wrote: Created #88873 for it. https://github.com/llvm/llvm-project/pull/85863 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits