[llvm] [IR] Remove support for shl constant expressions (PR #96037)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 19 07:23:19 PDT 2024


https://github.com/nikic updated https://github.com/llvm/llvm-project/pull/96037

>From f5b020d95bda3b9aa2b10c597a5c0e8c1c003c5f Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Wed, 19 Jun 2024 09:29:36 +0200
Subject: [PATCH 1/2] [IR] Remove support for shl constant expressions

Remove support for shl constant expressions, as part of:
https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179
---
 llvm/bindings/ocaml/llvm/llvm.ml              |  1 -
 llvm/bindings/ocaml/llvm/llvm.mli             |  5 --
 llvm/bindings/ocaml/llvm/llvm_ocaml.c         |  6 --
 llvm/docs/ReleaseNotes.rst                    |  2 +
 llvm/include/llvm-c/Core.h                    |  1 -
 llvm/include/llvm/IR/Constants.h              | 10 ---
 llvm/lib/AsmParser/LLParser.cpp               |  3 +-
 llvm/lib/IR/ConstantFold.cpp                  | 68 -------------------
 llvm/lib/IR/Constants.cpp                     | 15 +---
 llvm/lib/IR/Core.cpp                          |  5 --
 .../2003-05-21-MalformedShiftCrash.ll         |  5 --
 llvm/test/Assembler/flags.ll                  |  6 --
 llvm/test/Transforms/InstCombine/rotate.ll    |  6 +-
 .../Transforms/InstCombine/shift-logic.ll     |  6 +-
 .../Transforms/InstCombine/udiv-simplify.ll   |  9 +--
 .../Transforms/LoopStrengthReduce/pr2537.ll   |  6 +-
 llvm/test/Verifier/ifunc-opaque.ll            |  2 +-
 llvm/unittests/IR/ConstantsTest.cpp           |  8 +--
 18 files changed, 24 insertions(+), 140 deletions(-)
 delete mode 100644 llvm/test/Assembler/2003-05-21-MalformedShiftCrash.ll

diff --git a/llvm/bindings/ocaml/llvm/llvm.ml b/llvm/bindings/ocaml/llvm/llvm.ml
index 7bfaf8656ab3f..86b010e0ac22d 100644
--- a/llvm/bindings/ocaml/llvm/llvm.ml
+++ b/llvm/bindings/ocaml/llvm/llvm.ml
@@ -651,7 +651,6 @@ external const_mul : llvalue -> llvalue -> llvalue = "llvm_const_mul"
 external const_nsw_mul : llvalue -> llvalue -> llvalue = "llvm_const_nsw_mul"
 external const_nuw_mul : llvalue -> llvalue -> llvalue = "llvm_const_nuw_mul"
 external const_xor : llvalue -> llvalue -> llvalue = "llvm_const_xor"
-external const_shl : llvalue -> llvalue -> llvalue = "llvm_const_shl"
 external const_gep : lltype -> llvalue -> llvalue array -> llvalue
                    = "llvm_const_gep"
 external const_in_bounds_gep : lltype -> llvalue -> llvalue array -> llvalue
diff --git a/llvm/bindings/ocaml/llvm/llvm.mli b/llvm/bindings/ocaml/llvm/llvm.mli
index 89b894b35849d..c16530d3a70cb 100644
--- a/llvm/bindings/ocaml/llvm/llvm.mli
+++ b/llvm/bindings/ocaml/llvm/llvm.mli
@@ -1136,11 +1136,6 @@ val const_nuw_mul : llvalue -> llvalue -> llvalue
     See the method [llvm::ConstantExpr::getXor]. *)
 val const_xor : llvalue -> llvalue -> llvalue
 
-(** [const_shl c1 c2] returns the constant integer [c1] left-shifted by the
-    constant integer [c2].
-    See the method [llvm::ConstantExpr::getShl]. *)
-val const_shl : llvalue -> llvalue -> llvalue
-
 (** [const_gep srcty pc indices] returns the constant [getElementPtr] of [pc]
     with source element type [srcty] and the constant integers indices from the
     array [indices].
diff --git a/llvm/bindings/ocaml/llvm/llvm_ocaml.c b/llvm/bindings/ocaml/llvm/llvm_ocaml.c
index 3976a96a6da9b..4ac824cd6a98a 100644
--- a/llvm/bindings/ocaml/llvm/llvm_ocaml.c
+++ b/llvm/bindings/ocaml/llvm/llvm_ocaml.c
@@ -1224,12 +1224,6 @@ value llvm_const_xor(value LHS, value RHS) {
   return to_val(Value);
 }
 
-/* llvalue -> llvalue -> llvalue */
-value llvm_const_shl(value LHS, value RHS) {
-  LLVMValueRef Value = LLVMConstShl(Value_val(LHS), Value_val(RHS));
-  return to_val(Value);
-}
-
 /* lltype -> llvalue -> llvalue array -> llvalue */
 value llvm_const_gep(value Ty, value ConstantVal, value Indices) {
   mlsize_t Length = Wosize_val(Indices);
diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index 507f6b20b11b5..abbb0596101fd 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -66,6 +66,7 @@ Changes to the LLVM IR
 
   * ``icmp``
   * ``fcmp``
+  * ``shl``
 * LLVM has switched from using debug intrinsics in textual IR to using debug
   records by default. Details of the change and instructions on how to update
   any downstream tools and tests can be found in the `migration docs
@@ -227,6 +228,7 @@ Changes to the C API
 
   * ``LLVMConstICmp``
   * ``LLVMConstFCmp``
+  * ``LLVMConstShl``
 
 **Note:** The following changes are due to the removal of the debug info
 intrinsics from LLVM and to the introduction of debug records into LLVM.
diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h
index 7de99c3a6038d..af2e562fe0f8d 100644
--- a/llvm/include/llvm-c/Core.h
+++ b/llvm/include/llvm-c/Core.h
@@ -2354,7 +2354,6 @@ LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
 LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
 LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
 LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
-LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
 LLVMValueRef LLVMConstGEP2(LLVMTypeRef Ty, LLVMValueRef ConstantVal,
                            LLVMValueRef *ConstantIndices, unsigned NumIndices);
 LLVMValueRef LLVMConstInBoundsGEP2(LLVMTypeRef Ty, LLVMValueRef ConstantVal,
diff --git a/llvm/include/llvm/IR/Constants.h b/llvm/include/llvm/IR/Constants.h
index 0ccccab9721c7..4d13c3880c692 100644
--- a/llvm/include/llvm/IR/Constants.h
+++ b/llvm/include/llvm/IR/Constants.h
@@ -1122,8 +1122,6 @@ class ConstantExpr : public Constant {
   static Constant *getMul(Constant *C1, Constant *C2, bool HasNUW = false,
                           bool HasNSW = false);
   static Constant *getXor(Constant *C1, Constant *C2);
-  static Constant *getShl(Constant *C1, Constant *C2, bool HasNUW = false,
-                          bool HasNSW = false);
   static Constant *getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced = false);
   static Constant *getPtrToInt(Constant *C, Type *Ty,
                                bool OnlyIfReduced = false);
@@ -1160,14 +1158,6 @@ class ConstantExpr : public Constant {
     return getMul(C1, C2, true, false);
   }
 
-  static Constant *getNSWShl(Constant *C1, Constant *C2) {
-    return getShl(C1, C2, false, true);
-  }
-
-  static Constant *getNUWShl(Constant *C1, Constant *C2) {
-    return getShl(C1, C2, true, false);
-  }
-
   /// If C is a scalar/fixed width vector of known powers of 2, then this
   /// function returns a new scalar/fixed width vector obtained from logBase2
   /// of C. Undef vector elements are set to zero.
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index 6ca80e34907fc..b086471404246 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -4157,6 +4157,8 @@ bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) {
     return error(ID.Loc, "lshr constexprs are no longer supported");
   case lltok::kw_ashr:
     return error(ID.Loc, "ashr constexprs are no longer supported");
+  case lltok::kw_shl:
+    return error(ID.Loc, "shl constexprs are no longer supported");
   case lltok::kw_fneg:
     return error(ID.Loc, "fneg constexprs are no longer supported");
   case lltok::kw_select:
@@ -4186,7 +4188,6 @@ bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) {
   case lltok::kw_add:
   case lltok::kw_sub:
   case lltok::kw_mul:
-  case lltok::kw_shl:
   case lltok::kw_xor: {
     bool NUW = false;
     bool NSW = false;
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp
index 34bcf36ec212c..693674ae0d06f 100644
--- a/llvm/lib/IR/ConstantFold.cpp
+++ b/llvm/lib/IR/ConstantFold.cpp
@@ -120,66 +120,6 @@ static Constant *FoldBitCast(Constant *V, Type *DestTy) {
   return nullptr;
 }
 
-
-/// V is an integer constant which only has a subset of its bytes used.
-/// The bytes used are indicated by ByteStart (which is the first byte used,
-/// counting from the least significant byte) and ByteSize, which is the number
-/// of bytes used.
-///
-/// This function analyzes the specified constant to see if the specified byte
-/// range can be returned as a simplified constant.  If so, the constant is
-/// returned, otherwise null is returned.
-static Constant *ExtractConstantBytes(Constant *C, unsigned ByteStart,
-                                      unsigned ByteSize) {
-  assert(C->getType()->isIntegerTy() &&
-         (cast<IntegerType>(C->getType())->getBitWidth() & 7) == 0 &&
-         "Non-byte sized integer input");
-  [[maybe_unused]] unsigned CSize = cast<IntegerType>(C->getType())->getBitWidth()/8;
-  assert(ByteSize && "Must be accessing some piece");
-  assert(ByteStart+ByteSize <= CSize && "Extracting invalid piece from input");
-  assert(ByteSize != CSize && "Should not extract everything");
-
-  // Constant Integers are simple.
-  if (ConstantInt *CI = dyn_cast<ConstantInt>(C)) {
-    APInt V = CI->getValue();
-    if (ByteStart)
-      V.lshrInPlace(ByteStart*8);
-    V = V.trunc(ByteSize*8);
-    return ConstantInt::get(CI->getContext(), V);
-  }
-
-  // In the input is a constant expr, we might be able to recursively simplify.
-  // If not, we definitely can't do anything.
-  ConstantExpr *CE = dyn_cast<ConstantExpr>(C);
-  if (!CE) return nullptr;
-
-  switch (CE->getOpcode()) {
-  default: return nullptr;
-  case Instruction::Shl: {
-    ConstantInt *Amt = dyn_cast<ConstantInt>(CE->getOperand(1));
-    if (!Amt)
-      return nullptr;
-    APInt ShAmt = Amt->getValue();
-    // Cannot analyze non-byte shifts.
-    if ((ShAmt & 7) != 0)
-      return nullptr;
-    ShAmt.lshrInPlace(3);
-
-    // If the extract is known to be all zeros, return zero.
-    if (ShAmt.uge(ByteStart + ByteSize))
-      return Constant::getNullValue(
-          IntegerType::get(CE->getContext(), ByteSize * 8));
-    // If the extract is known to be fully in the input, extract it.
-    if (ShAmt.ule(ByteStart))
-      return ExtractConstantBytes(CE->getOperand(0),
-                                  ByteStart - ShAmt.getZExtValue(), ByteSize);
-
-    // TODO: Handle the 'partially zero' case.
-    return nullptr;
-  }
-  }
-}
-
 static Constant *foldMaybeUndesirableCast(unsigned opc, Constant *V,
                                           Type *DestTy) {
   return ConstantExpr::isDesirableCastOp(opc)
@@ -313,14 +253,6 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, Constant *V,
                               CI->getValue().trunc(DestBitWidth));
     }
 
-    // The input must be a constantexpr.  See if we can simplify this based on
-    // the bytes we are demanding.  Only do this if the source and dest are an
-    // even multiple of a byte.
-    if ((DestBitWidth & 7) == 0 &&
-        (cast<IntegerType>(V->getType())->getBitWidth() & 7) == 0)
-      if (Constant *Res = ExtractConstantBytes(V, 0, DestBitWidth / 8))
-        return Res;
-
     return nullptr;
   }
   case Instruction::BitCast:
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp
index fed3670dd985b..bc91f904d7e87 100644
--- a/llvm/lib/IR/Constants.cpp
+++ b/llvm/lib/IR/Constants.cpp
@@ -2285,12 +2285,6 @@ Constant *ConstantExpr::get(unsigned Opcode, Constant *C1, Constant *C2,
     assert(C1->getType()->isIntOrIntVectorTy() &&
            "Tried to create a logical operation on a non-integral type!");
     break;
-  case Instruction::Shl:
-  case Instruction::LShr:
-  case Instruction::AShr:
-    assert(C1->getType()->isIntOrIntVectorTy() &&
-           "Tried to create a shift operation on a non-integer type!");
-    break;
   default:
     break;
   }
@@ -2351,11 +2345,11 @@ bool ConstantExpr::isSupportedBinOp(unsigned Opcode) {
   case Instruction::Or:
   case Instruction::LShr:
   case Instruction::AShr:
+  case Instruction::Shl:
     return false;
   case Instruction::Add:
   case Instruction::Sub:
   case Instruction::Mul:
-  case Instruction::Shl:
   case Instruction::Xor:
     return true;
   default:
@@ -2589,13 +2583,6 @@ Constant *ConstantExpr::getXor(Constant *C1, Constant *C2) {
   return get(Instruction::Xor, C1, C2);
 }
 
-Constant *ConstantExpr::getShl(Constant *C1, Constant *C2,
-                               bool HasNUW, bool HasNSW) {
-  unsigned Flags = (HasNUW ? OverflowingBinaryOperator::NoUnsignedWrap : 0) |
-                   (HasNSW ? OverflowingBinaryOperator::NoSignedWrap   : 0);
-  return get(Instruction::Shl, C1, C2, Flags);
-}
-
 Constant *ConstantExpr::getExactLogBase2(Constant *C) {
   Type *Ty = C->getType();
   const APInt *IVal;
diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp
index 3a91a4eb6e0d1..3b6b01fb78b0a 100644
--- a/llvm/lib/IR/Core.cpp
+++ b/llvm/lib/IR/Core.cpp
@@ -1746,11 +1746,6 @@ LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
                                    unwrap<Constant>(RHSConstant)));
 }
 
-LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
-  return wrap(ConstantExpr::getShl(unwrap<Constant>(LHSConstant),
-                                   unwrap<Constant>(RHSConstant)));
-}
-
 LLVMValueRef LLVMConstGEP2(LLVMTypeRef Ty, LLVMValueRef ConstantVal,
                            LLVMValueRef *ConstantIndices, unsigned NumIndices) {
   ArrayRef<Constant *> IdxList(unwrap<Constant>(ConstantIndices, NumIndices),
diff --git a/llvm/test/Assembler/2003-05-21-MalformedShiftCrash.ll b/llvm/test/Assembler/2003-05-21-MalformedShiftCrash.ll
deleted file mode 100644
index a0dda4553c9aa..0000000000000
--- a/llvm/test/Assembler/2003-05-21-MalformedShiftCrash.ll
+++ /dev/null
@@ -1,5 +0,0 @@
-; Found by inspection of the code
-; RUN: not llvm-as < %s > /dev/null 2> %t
-; RUN: grep "constexpr requires integer or integer vector operands" %t
-
- at 0 = global i32 shl (float 1.0, float 2.0)
diff --git a/llvm/test/Assembler/flags.ll b/llvm/test/Assembler/flags.ll
index 7d2aafa005e7f..84209500d27a5 100644
--- a/llvm/test/Assembler/flags.ll
+++ b/llvm/test/Assembler/flags.ll
@@ -230,12 +230,6 @@ define i64 @mul_signed_ce() {
 	ret i64 mul nsw (i64 ptrtoint (ptr @addr to i64), i64 91)
 }
 
-define i64 @shl_signed_ce() {
-; CHECK: ret i64 shl nsw (i64 ptrtoint (ptr @addr to i64), i64 17)
-	ret i64 shl nsw (i64 ptrtoint (ptr @addr to i64), i64 17)
-}
-
-
 define i64 @add_unsigned_ce() {
 ; CHECK: ret i64 add nuw (i64 ptrtoint (ptr @addr to i64), i64 91)
 	ret i64 add nuw (i64 ptrtoint (ptr @addr to i64), i64 91)
diff --git a/llvm/test/Transforms/InstCombine/rotate.ll b/llvm/test/Transforms/InstCombine/rotate.ll
index eec623e2f193a..35d15ea0bea23 100644
--- a/llvm/test/Transforms/InstCombine/rotate.ll
+++ b/llvm/test/Transforms/InstCombine/rotate.ll
@@ -893,11 +893,13 @@ define i64 @rotr_select_zext_shamt(i64 %x, i32 %y) {
 define i32 @rotl_constant_expr(i32 %shamt) {
 ; CHECK-LABEL: @rotl_constant_expr(
 ; CHECK-NEXT:    [[SHR:%.*]] = lshr i32 ptrtoint (ptr @external_global to i32), [[SHAMT:%.*]]
-; CHECK-NEXT:    [[R:%.*]] = or i32 [[SHR]], shl (i32 ptrtoint (ptr @external_global to i32), i32 11)
+; CHECK-NEXT:    [[SHL:%.*]] = shl i32 ptrtoint (ptr @external_global to i32), 11
+; CHECK-NEXT:    [[R:%.*]] = or i32 [[SHR]], [[SHL]]
 ; CHECK-NEXT:    ret i32 [[R]]
 ;
   %shr = lshr i32 ptrtoint (ptr @external_global to i32), %shamt
-  %r = or i32 %shr, shl (i32 ptrtoint (ptr @external_global to i32), i32 11)
+  %shl = shl i32 ptrtoint (ptr @external_global to i32), 11
+  %r = or i32 %shr, %shl
   ret i32 %r
 }
 
diff --git a/llvm/test/Transforms/InstCombine/shift-logic.ll b/llvm/test/Transforms/InstCombine/shift-logic.ll
index b591400c6a260..3d4547e0bb9ca 100644
--- a/llvm/test/Transforms/InstCombine/shift-logic.ll
+++ b/llvm/test/Transforms/InstCombine/shift-logic.ll
@@ -247,12 +247,14 @@ define i32 @lshr_or_extra_use(i32 %x, i32 %y, ptr %p) {
 define i32 @PR44028(i32 %x) {
 ; CHECK-LABEL: @PR44028(
 ; CHECK-NEXT:    [[SH1:%.*]] = ashr exact i32 [[X:%.*]], 16
-; CHECK-NEXT:    [[T0:%.*]] = xor i32 [[SH1]], shl (i32 ptrtoint (ptr @g to i32), i32 16)
+; CHECK-NEXT:    [[SH2:%.*]] = shl i32 ptrtoint (ptr @g to i32), 16
+; CHECK-NEXT:    [[T0:%.*]] = xor i32 [[SH1]], [[SH2]]
 ; CHECK-NEXT:    [[T27:%.*]] = ashr exact i32 [[T0]], 16
 ; CHECK-NEXT:    ret i32 [[T27]]
 ;
   %sh1 = ashr exact i32 %x, 16
-  %t0 = xor i32 %sh1, shl (i32 ptrtoint (ptr @g to i32), i32 16)
+  %sh2 = shl i32 ptrtoint (ptr @g to i32), 16
+  %t0 = xor i32 %sh1, %sh2
   %t27 = ashr exact i32 %t0, 16
   ret i32 %t27
 }
diff --git a/llvm/test/Transforms/InstCombine/udiv-simplify.ll b/llvm/test/Transforms/InstCombine/udiv-simplify.ll
index bd6e5efc05f18..0af334842ac05 100644
--- a/llvm/test/Transforms/InstCombine/udiv-simplify.ll
+++ b/llvm/test/Transforms/InstCombine/udiv-simplify.ll
@@ -55,12 +55,13 @@ define i64 @test2_PR2274(i32 %x, i32 %v) nounwind {
 define i32 @PR30366(i1 %a) {
 ; CHECK-LABEL: @PR30366(
 ; CHECK-NEXT:    [[Z:%.*]] = zext i1 [[A:%.*]] to i32
-; CHECK-NEXT:    [[Z2:%.*]] = zext nneg i16 shl (i16 1, i16 ptrtoint (ptr @b to i16)) to i32
-; CHECK-NEXT:    [[D:%.*]] = udiv i32 [[Z]], [[Z2]]
-; CHECK-NEXT:    ret i32 [[D]]
+; CHECK-NEXT:    [[TMP1:%.*]] = zext nneg i16 ptrtoint (ptr @b to i16) to i32
+; CHECK-NEXT:    [[D1:%.*]] = lshr i32 [[Z]], [[TMP1]]
+; CHECK-NEXT:    ret i32 [[D1]]
 ;
   %z = zext i1 %a to i32
-  %z2 = zext i16 shl (i16 1, i16 ptrtoint (ptr @b to i16)) to i32
+  %shl = shl i16 1, ptrtoint (ptr @b to i16)
+  %z2 = zext i16 %shl to i32
   %d = udiv i32 %z, %z2
   ret i32 %d
 }
diff --git a/llvm/test/Transforms/LoopStrengthReduce/pr2537.ll b/llvm/test/Transforms/LoopStrengthReduce/pr2537.ll
index 46ad70e736d83..d92323ce89a15 100644
--- a/llvm/test/Transforms/LoopStrengthReduce/pr2537.ll
+++ b/llvm/test/Transforms/LoopStrengthReduce/pr2537.ll
@@ -8,10 +8,10 @@ entry:
 dobody:         ; preds = %dobody, %entry
         %y.0 = phi i128 [ 0, %entry ], [ %add, %dobody ]
         %x.0 = phi i128 [ 0, %entry ], [ %add2, %dobody ]
-        %add = add i128 %y.0, shl (i128 1, i128 64)
-        %add2 = add i128 %x.0, shl (i128 1, i128 48)
+        %add = add i128 %y.0, u0x10000000000000000
+        %add2 = add i128 %x.0, u0x1000000000000
         call void @b( i128 %add )
-        %cmp = icmp ult i128 %add2, shl (i128 1, i128 64)
+        %cmp = icmp ult i128 %add2, u0x10000000000000000
         br i1 %cmp, label %dobody, label %afterdo
 
 afterdo:                ; preds = %dobody
diff --git a/llvm/test/Verifier/ifunc-opaque.ll b/llvm/test/Verifier/ifunc-opaque.ll
index 349207b429ebd..a1505c3c0ab9b 100644
--- a/llvm/test/Verifier/ifunc-opaque.ll
+++ b/llvm/test/Verifier/ifunc-opaque.ll
@@ -14,4 +14,4 @@ define ptr @resolver() {
 
 ; CHECK: IFunc must have a Function resolver
 ; CHECK-NEXT: ptr @ifunc_shl
- at ifunc_shl = ifunc void (), ptr inttoptr (i64 shl (i64 ptrtoint (ptr @resolver to i64), i64 4) to ptr)
+ at ifunc_shl = ifunc void (), ptr inttoptr (i64 add (i64 ptrtoint (ptr @resolver to i64), i64 4) to ptr)
diff --git a/llvm/unittests/IR/ConstantsTest.cpp b/llvm/unittests/IR/ConstantsTest.cpp
index 2a85aac55711c..48d65be70b37b 100644
--- a/llvm/unittests/IR/ConstantsTest.cpp
+++ b/llvm/unittests/IR/ConstantsTest.cpp
@@ -56,11 +56,11 @@ TEST(ConstantsTest, Integer_i1) {
 
   // @h = constant i1 shl(i1 1 , i1 1)  ; poison
   // @h = constant i1 poison
-  EXPECT_EQ(Poison, ConstantExpr::getShl(One, One));
+  EXPECT_EQ(Poison, ConstantFoldBinaryInstruction(Instruction::Shl, One, One));
 
   // @i = constant i1 shl(i1 1 , i1 0)
   // @i = constant i1 true
-  EXPECT_EQ(One, ConstantExpr::getShl(One, Zero));
+  EXPECT_EQ(One, ConstantFoldBinaryInstruction(Instruction::Shl, One, Zero));
 
   // @n = constant i1 mul(i1 -1, i1 1)
   // @n = constant i1 true
@@ -216,10 +216,6 @@ TEST(ConstantsTest, AsInstructionsTest) {
   CHECK(ConstantExpr::getSub(P0, P0), "sub i32 " P0STR ", " P0STR);
   CHECK(ConstantExpr::getMul(P0, P0), "mul i32 " P0STR ", " P0STR);
   CHECK(ConstantExpr::getXor(P0, P0), "xor i32 " P0STR ", " P0STR);
-  CHECK(ConstantExpr::getShl(P0, P0), "shl i32 " P0STR ", " P0STR);
-  CHECK(ConstantExpr::getShl(P0, P0, true), "shl nuw i32 " P0STR ", " P0STR);
-  CHECK(ConstantExpr::getShl(P0, P0, false, true),
-        "shl nsw i32 " P0STR ", " P0STR);
 
   std::vector<Constant *> V;
   V.push_back(One);

>From 7bc80d8b203b4fa89de91707ee5330435783c9a0 Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Wed, 19 Jun 2024 16:21:19 +0200
Subject: [PATCH 2/2] Remove shl handling in asmparser

---
 llvm/lib/AsmParser/LLParser.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index b086471404246..6c97e9e943b3f 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -4195,7 +4195,7 @@ bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) {
     Constant *Val0, *Val1;
     Lex.Lex();
     if (Opc == Instruction::Add || Opc == Instruction::Sub ||
-        Opc == Instruction::Mul || Opc == Instruction::Shl) {
+        Opc == Instruction::Mul) {
       if (EatIfPresent(lltok::kw_nuw))
         NUW = true;
       if (EatIfPresent(lltok::kw_nsw)) {



More information about the llvm-commits mailing list