[llvm] [clang] [Instcombine] use zext's nneg flag for icmp folding (PR #70845)

LĂ©onard Oest O'Leary via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 10 11:49:14 PST 2023


================
@@ -247,6 +355,19 @@ define i1 @sext_zext_uge_op0_wide(i16 %x, i8 %y) {
   ret i1 %c
 }
 
+
+define i1 @sext_zext_nneg_uge_op0_wide(i16 %x, i8 %y) {
+; CHECK-LABEL: @sext_zext_nneg_uge_op0_wide(
+; CHECK-NEXT:    [[TMP1:%.*]] = sext i8 [[Y:%.*]] to i16
+; CHECK-NEXT:    [[C:%.*]] = icmp ule i16 [[TMP1]], [[X:%.*]]
+; CHECK-NEXT:    ret i1 [[C]]
+;
+  %a = sext i16 %x to i32
+  %b = zext nneg i8 %y to i32
+  %c = icmp uge i32 %a, %b
+  ret i1 %c
+}
+
 define i1 @zext_sext_sgt_known_nonneg(i8 %x, i8 %y) {
 ; CHECK-LABEL: @zext_sext_sgt_known_nonneg(
----------------
leo-ard wrote:

Every test in this test-file has an `known_nonneg` variant for mismatched zext/sext. I was wondering on the relevance of this variant as we now have the nneg flag on zext. It would make more sense to have specialized tests for zext -> zext nneg folding with value-tracking and another test for icmp with zext nneg/sext folding into icmp (what I just added). FYI, this test dates from this PR, when there where no nneg flag : https://reviews.llvm.org/D124419. 

https://github.com/llvm/llvm-project/pull/70845


More information about the cfe-commits mailing list