[llvm] [InstCombine] Fold `sext(trunc nsw)` and `zext(trunc nuw)` (PR #88609)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 13 04:15:07 PDT 2024


================
@@ -423,3 +423,44 @@ define i64 @smear_set_bit_different_dest_type_wider_dst(i32 %x) {
   %s = sext i8 %a to i64
   ret i64 %s
 }
+
+define i32 @sext_trunc_nsw(i16 %x) {
+; CHECK-LABEL: @sext_trunc_nsw(
+; CHECK-NEXT:    [[E:%.*]] = sext i16 [[X:%.*]] to i32
+; CHECK-NEXT:    ret i32 [[E]]
+;
+  %c = trunc nsw i16 %x to i8
+  %e = sext i8 %c to i32
+  ret i32 %e
+}
----------------
nikic wrote:

Also test the case where the type matches exactly and we optimize to nothing? (Also for zext).

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


More information about the llvm-commits mailing list