فهرست منبع

Slightly simplify int value lowering. (#4767)

Refactor to use the new `GetAtWidth` function.
Richard Smith 1 سال پیش
والد
کامیت
f6d0cdabf8
1فایلهای تغییر یافته به همراه2 افزوده شده و 5 حذف شده
  1. 2 5
      toolchain/lower/constant.cpp

+ 2 - 5
toolchain/lower/constant.cpp

@@ -199,12 +199,9 @@ static auto EmitAsConstant(ConstantContext& context, SemIR::IntValue inst)
     return int_literal_value;
   }
 
-  auto val = context.sem_ir().ints().Get(inst.int_id);
   int bit_width = int_type->getBitWidth();
-  bool is_signed =
-      context.sem_ir().types().GetIntTypeInfo(inst.type_id).is_signed;
-  return llvm::ConstantInt::get(type, is_signed ? val.sextOrTrunc(bit_width)
-                                                : val.zextOrTrunc(bit_width));
+  auto val = context.sem_ir().ints().GetAtWidth(inst.int_id, bit_width);
+  return llvm::ConstantInt::get(type, val);
 }
 
 static auto EmitAsConstant(ConstantContext& context, SemIR::Namespace inst)