[clang] [llvm] [IR] Mark vector intrinsics speculatable (PR #162334)

Ramkumar Ramachandra via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 8 14:02:17 PDT 2025


================
@@ -10,30 +10,30 @@
 // CHECK-C-SAME: i32 noundef [[SLICE_BASE:%.*]], <vscale x 16 x i1> [[PG:%.*]], ptr noundef [[PTR:%.*]], i64 noundef [[VNUM:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
 // CHECK-C-NEXT:  entry:
 // CHECK-C-NEXT:    [[TMP0:%.*]] = tail call i64 @llvm.vscale.i64()
-// CHECK-C-NEXT:    [[TMP1:%.*]] = shl i64 [[VNUM]], 4
-// CHECK-C-NEXT:    [[MULVL:%.*]] = mul i64 [[TMP1]], [[TMP0]]
-// CHECK-C-NEXT:    [[TMP2:%.*]] = getelementptr i8, ptr [[PTR]], i64 [[MULVL]]
-// CHECK-C-NEXT:    [[TMP3:%.*]] = trunc i64 [[VNUM]] to i32
-// CHECK-C-NEXT:    [[TMP4:%.*]] = add i32 [[SLICE_BASE]], [[TMP3]]
-// CHECK-C-NEXT:    tail call void @llvm.aarch64.sme.ld1b.horiz(<vscale x 16 x i1> [[PG]], ptr [[TMP2]], i32 0, i32 [[TMP4]])
-// CHECK-C-NEXT:    [[ADD:%.*]] = add i32 [[SLICE_BASE]], [[TMP3]]
-// CHECK-C-NEXT:    [[TMP5:%.*]] = add i32 [[ADD]], 15
-// CHECK-C-NEXT:    tail call void @llvm.aarch64.sme.ld1b.horiz(<vscale x 16 x i1> [[PG]], ptr [[TMP2]], i32 0, i32 [[TMP5]])
+// CHECK-C-NEXT:    [[SVL:%.*]] = shl nuw nsw i64 [[TMP0]], 4
----------------
artagnon wrote:

I think I finally found the piece of code that sets nuw/nsw:

```cpp
Value *llvm::emitGEPOffset(IRBuilderBase *Builder, const DataLayout &DL,
                           User *GEP, bool NoAssumptions) {
  // ...
  // nusw implies nsw for the offset arithmetic.
  bool NSW = GEPOp->hasNoUnsignedSignedWrap() && !NoAssumptions;
  bool NUW = GEPOp->hasNoUnsignedWrap() && !NoAssumptions;
```

There are several places in InstructionCombining that determine `nuw nusw` on the GEP. Finally, what this has to do with speculative execution:

```cpp
  if (!isSafeToSpeculativelyExecuteWithVariableReplaced(&Inst))
    return nullptr;
```

... in foldVectorBinOp.

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


More information about the cfe-commits mailing list