[llvm] [InstCombine] Fold `(icmp pred (trunc nuw/nsw X), C)` -> `(icmp pred X, (zext/sext C))` (PR #87935)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 9 02:01:08 PDT 2024


================
@@ -555,3 +555,147 @@ define i1 @shl1_trunc_sgt4(i32 %a) {
   %r = icmp sgt i16 %t, 4
   ret i1 %r
 }
+
+define i1 @eq_nuw(i32 %x) {
+; DL64-LABEL: @eq_nuw(
+; DL64-NEXT:    [[TMP1:%.*]] = and i32 [[X:%.*]], 255
+; DL64-NEXT:    [[R:%.*]] = icmp eq i32 [[TMP1]], 123
+; DL64-NEXT:    ret i1 [[R]]
----------------
nikic wrote:

Presumably https://github.com/llvm/llvm-project/blob/42fc67c924dae62e70099f35dbdf3f839d06631c/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp#L1460. Your new fold should preferably run before that. Why do we have both foldICmpWithTrunc and foldICmpTruncConstant that both handle trunc + constant...

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


More information about the llvm-commits mailing list