Skip to content

Commit 2f0d1c5

Browse files
committed
Tests
1 parent 8bb2eca commit 2f0d1c5

File tree

2 files changed

+120
-32
lines changed

2 files changed

+120
-32
lines changed

llvm/test/Transforms/InstSimplify/constfold-constrained.ll

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ entry:
1717
define double @floor_02() #0 {
1818
; CHECK-LABEL: @floor_02(
1919
; CHECK-NEXT: entry:
20-
; CHECK-NEXT: [[RESULT:%.*]] = call double @llvm.experimental.constrained.floor.f64(double -1.010000e+01, metadata !"fpexcept.strict") #[[ATTR3:[0-9]+]] [ "fp.except"(metadata !"strict") ]
20+
; CHECK-NEXT: [[RESULT:%.*]] = call double @llvm.experimental.constrained.floor.f64(double -1.010000e+01, metadata !"fpexcept.strict") #[[ATTR0:[0-9]+]]
2121
; CHECK-NEXT: ret double -1.100000e+01
2222
;
2323
entry:
@@ -40,7 +40,7 @@ entry:
4040
define double @ceil_02() #0 {
4141
; CHECK-LABEL: @ceil_02(
4242
; CHECK-NEXT: entry:
43-
; CHECK-NEXT: [[RESULT:%.*]] = call double @llvm.experimental.constrained.ceil.f64(double -1.010000e+01, metadata !"fpexcept.strict") #[[ATTR3]] [ "fp.except"(metadata !"strict") ]
43+
; CHECK-NEXT: [[RESULT:%.*]] = call double @llvm.experimental.constrained.ceil.f64(double -1.010000e+01, metadata !"fpexcept.strict") #[[ATTR0]]
4444
; CHECK-NEXT: ret double -1.000000e+01
4545
;
4646
entry:
@@ -63,11 +63,11 @@ entry:
6363
define double @trunc_02() #0 {
6464
; CHECK-LABEL: @trunc_02(
6565
; CHECK-NEXT: entry:
66-
; CHECK-NEXT: [[RESULT:%.*]] = call double @llvm.trunc.f64(double -1.010000e+01) #[[ATTR3]] [ "fp.except"(metadata !"strict") ]
66+
; CHECK-NEXT: [[RESULT:%.*]] = call double @llvm.trunc.f64(double -1.010000e+01) #0 [ "fp.except"(metadata !"strict") ]
6767
; CHECK-NEXT: ret double -1.000000e+01
6868
;
6969
entry:
70-
%result = call double @llvm.trunc.f64(double -1.010000e+01, metadata !"fpexcept.strict") #0 [ "fp.except"(metadata !"strict") ]
70+
%result = call double @llvm.trunc.f64(double -1.010000e+01) #0 [ "fp.except"(metadata !"strict") ]
7171
ret double %result
7272
}
7373

@@ -86,7 +86,7 @@ entry:
8686
define double @round_02() #0 {
8787
; CHECK-LABEL: @round_02(
8888
; CHECK-NEXT: entry:
89-
; CHECK-NEXT: [[RESULT:%.*]] = call double @llvm.experimental.constrained.round.f64(double -1.050000e+01, metadata !"fpexcept.strict") #[[ATTR3]] [ "fp.except"(metadata !"strict") ]
89+
; CHECK-NEXT: [[RESULT:%.*]] = call double @llvm.experimental.constrained.round.f64(double -1.050000e+01, metadata !"fpexcept.strict") #[[ATTR0]]
9090
; CHECK-NEXT: ret double -1.100000e+01
9191
;
9292
entry:
@@ -120,7 +120,7 @@ entry:
120120
define double @nearbyint_03() #0 {
121121
; CHECK-LABEL: @nearbyint_03(
122122
; CHECK-NEXT: entry:
123-
; CHECK-NEXT: [[RESULT:%.*]] = call double @llvm.experimental.constrained.nearbyint.f64(double 1.050000e+01, metadata !"round.towardzero", metadata !"fpexcept.strict") #[[ATTR3]] [ "fp.control"(metadata !"rtz"), "fp.except"(metadata !"strict") ]
123+
; CHECK-NEXT: [[RESULT:%.*]] = call double @llvm.experimental.constrained.nearbyint.f64(double 1.050000e+01, metadata !"round.towardzero", metadata !"fpexcept.strict") #[[ATTR0]]
124124
; CHECK-NEXT: ret double 1.000000e+01
125125
;
126126
entry:
@@ -132,7 +132,7 @@ entry:
132132
define double @nearbyint_04() #0 {
133133
; CHECK-LABEL: @nearbyint_04(
134134
; CHECK-NEXT: entry:
135-
; CHECK-NEXT: [[RESULT:%.*]] = call double @llvm.experimental.constrained.nearbyint.f64(double 1.050000e+01, metadata !"round.tonearest", metadata !"fpexcept.strict") #[[ATTR3]] [ "fp.control"(metadata !"rte"), "fp.except"(metadata !"strict") ]
135+
; CHECK-NEXT: [[RESULT:%.*]] = call double @llvm.experimental.constrained.nearbyint.f64(double 1.050000e+01, metadata !"round.tonearest", metadata !"fpexcept.strict") #[[ATTR0]]
136136
; CHECK-NEXT: ret double 1.000000e+01
137137
;
138138
entry:
@@ -144,7 +144,7 @@ entry:
144144
define double @nearbyint_05() #0 {
145145
; CHECK-LABEL: @nearbyint_05(
146146
; CHECK-NEXT: entry:
147-
; CHECK-NEXT: [[RESULT:%.*]] = call double @llvm.experimental.constrained.nearbyint.f64(double 1.050000e+01, metadata !"round.dynamic", metadata !"fpexcept.strict") #[[ATTR3]] [ "fp.control"(metadata !"dyn"), "fp.except"(metadata !"strict") ]
147+
; CHECK-NEXT: [[RESULT:%.*]] = call double @llvm.experimental.constrained.nearbyint.f64(double 1.050000e+01, metadata !"round.dynamic", metadata !"fpexcept.strict") #[[ATTR0]]
148148
; CHECK-NEXT: ret double [[RESULT]]
149149
;
150150
entry:
@@ -156,11 +156,11 @@ entry:
156156
define double @nonfinite_01() #0 {
157157
; CHECK-LABEL: @nonfinite_01(
158158
; CHECK-NEXT: entry:
159-
; CHECK-NEXT: [[RESULT:%.*]] = call double @llvm.trunc.f64(double 0x7FF4000000000000) #[[ATTR3]] [ "fp.except"(metadata !"strict") ]
159+
; CHECK-NEXT: [[RESULT:%.*]] = call double @llvm.trunc.f64(double 0x7FF4000000000000) #0 [ "fp.except"(metadata !"strict") ]
160160
; CHECK-NEXT: ret double [[RESULT]]
161161
;
162162
entry:
163-
%result = call double @llvm.trunc.f64(double 0x7ff4000000000000, metadata !"fpexcept.strict") #0 [ "fp.except"(metadata !"strict") ]
163+
%result = call double @llvm.trunc.f64(double 0x7ff4000000000000) #0 [ "fp.except"(metadata !"strict") ]
164164
ret double %result
165165
}
166166

@@ -179,7 +179,7 @@ entry:
179179
define double @nonfinite_03() #0 {
180180
; CHECK-LABEL: @nonfinite_03(
181181
; CHECK-NEXT: entry:
182-
; CHECK-NEXT: [[RESULT:%.*]] = call double @llvm.trunc.f64(double 0x7FF8000000000000) #[[ATTR3]] [ "fp.except"(metadata !"strict") ]
182+
; CHECK-NEXT: [[RESULT:%.*]] = call double @llvm.trunc.f64(double 0x7FF8000000000000) #0 [ "fp.except"(metadata !"strict") ]
183183
; CHECK-NEXT: ret double 0x7FF8000000000000
184184
;
185185
entry:
@@ -191,7 +191,7 @@ entry:
191191
define double @nonfinite_04() #0 {
192192
; CHECK-LABEL: @nonfinite_04(
193193
; CHECK-NEXT: entry:
194-
; CHECK-NEXT: [[RESULT:%.*]] = call double @llvm.trunc.f64(double 0x7FF0000000000000) #[[ATTR3]] [ "fp.except"(metadata !"strict") ]
194+
; CHECK-NEXT: [[RESULT:%.*]] = call double @llvm.trunc.f64(double 0x7FF0000000000000) #0 [ "fp.except"(metadata !"strict") ]
195195
; CHECK-NEXT: ret double 0x7FF0000000000000
196196
;
197197
entry:
@@ -203,7 +203,7 @@ entry:
203203
define double @rint_01() #0 {
204204
; CHECK-LABEL: @rint_01(
205205
; CHECK-NEXT: entry:
206-
; CHECK-NEXT: [[RESULT:%.*]] = call double @llvm.experimental.constrained.rint.f64(double 1.000000e+01, metadata !"round.tonearest", metadata !"fpexcept.strict") #[[ATTR3]] [ "fp.control"(metadata !"rte"), "fp.except"(metadata !"strict") ]
206+
; CHECK-NEXT: [[RESULT:%.*]] = call double @llvm.experimental.constrained.rint.f64(double 1.000000e+01, metadata !"round.tonearest", metadata !"fpexcept.strict") #[[ATTR0]]
207207
; CHECK-NEXT: ret double 1.000000e+01
208208
;
209209
entry:
@@ -215,7 +215,7 @@ entry:
215215
define double @rint_02() #0 {
216216
; CHECK-LABEL: @rint_02(
217217
; CHECK-NEXT: entry:
218-
; CHECK-NEXT: [[RESULT:%.*]] = call double @llvm.experimental.constrained.rint.f64(double 1.010000e+01, metadata !"round.tonearest", metadata !"fpexcept.strict") #[[ATTR3]] [ "fp.control"(metadata !"rte"), "fp.except"(metadata !"strict") ]
218+
; CHECK-NEXT: [[RESULT:%.*]] = call double @llvm.experimental.constrained.rint.f64(double 1.010000e+01, metadata !"round.tonearest", metadata !"fpexcept.strict") #[[ATTR0]]
219219
; CHECK-NEXT: ret double [[RESULT]]
220220
;
221221
entry:
@@ -270,7 +270,7 @@ entry:
270270
define double @fadd_04() #0 {
271271
; CHECK-LABEL: @fadd_04(
272272
; CHECK-NEXT: entry:
273-
; CHECK-NEXT: [[RESULT:%.*]] = call double @llvm.experimental.constrained.fadd.f64(double 1.000000e+00, double 0x3FF0000000000001, metadata !"round.tonearest", metadata !"fpexcept.strict") #[[ATTR3]] [ "fp.control"(metadata !"rte"), "fp.except"(metadata !"strict") ]
273+
; CHECK-NEXT: [[RESULT:%.*]] = call double @llvm.experimental.constrained.fadd.f64(double 1.000000e+00, double 0x3FF0000000000001, metadata !"round.tonearest", metadata !"fpexcept.strict") #[[ATTR0]]
274274
; CHECK-NEXT: ret double [[RESULT]]
275275
;
276276
entry:
@@ -282,7 +282,7 @@ entry:
282282
define double @fadd_05() #0 {
283283
; CHECK-LABEL: @fadd_05(
284284
; CHECK-NEXT: entry:
285-
; CHECK-NEXT: [[RESULT:%.*]] = call double @llvm.experimental.constrained.fadd.f64(double 1.000000e+00, double 2.000000e+00, metadata !"round.tonearest", metadata !"fpexcept.strict") #[[ATTR3]] [ "fp.control"(metadata !"rte"), "fp.except"(metadata !"strict") ]
285+
; CHECK-NEXT: [[RESULT:%.*]] = call double @llvm.experimental.constrained.fadd.f64(double 1.000000e+00, double 2.000000e+00, metadata !"round.tonearest", metadata !"fpexcept.strict") #[[ATTR0]]
286286
; CHECK-NEXT: ret double 3.000000e+00
287287
;
288288
entry:
@@ -294,7 +294,7 @@ entry:
294294
define double @fadd_06() #0 {
295295
; CHECK-LABEL: @fadd_06(
296296
; CHECK-NEXT: entry:
297-
; CHECK-NEXT: [[RESULT:%.*]] = call double @llvm.experimental.constrained.fadd.f64(double 1.000000e+00, double 2.000000e+00, metadata !"round.dynamic", metadata !"fpexcept.strict") #[[ATTR3]] [ "fp.control"(metadata !"dyn"), "fp.except"(metadata !"strict") ]
297+
; CHECK-NEXT: [[RESULT:%.*]] = call double @llvm.experimental.constrained.fadd.f64(double 1.000000e+00, double 2.000000e+00, metadata !"round.dynamic", metadata !"fpexcept.strict") #[[ATTR0]]
298298
; CHECK-NEXT: ret double 3.000000e+00
299299
;
300300
entry:
@@ -306,7 +306,7 @@ entry:
306306
define double @fadd_07() #0 {
307307
; CHECK-LABEL: @fadd_07(
308308
; CHECK-NEXT: entry:
309-
; CHECK-NEXT: [[RESULT:%.*]] = call double @llvm.experimental.constrained.fadd.f64(double 1.000000e+00, double 0x3FF0000000000001, metadata !"round.dynamic", metadata !"fpexcept.ignore") #[[ATTR3]] [ "fp.control"(metadata !"dyn"), "fp.except"(metadata !"ignore") ]
309+
; CHECK-NEXT: [[RESULT:%.*]] = call double @llvm.experimental.constrained.fadd.f64(double 1.000000e+00, double 0x3FF0000000000001, metadata !"round.dynamic", metadata !"fpexcept.ignore") #[[ATTR0]]
310310
; CHECK-NEXT: ret double [[RESULT]]
311311
;
312312
entry:
@@ -328,7 +328,7 @@ entry:
328328
define double @fadd_09() #0 {
329329
; CHECK-LABEL: @fadd_09(
330330
; CHECK-NEXT: entry:
331-
; CHECK-NEXT: [[RESULT:%.*]] = call double @llvm.experimental.constrained.fadd.f64(double 0x7FEFFFFFFFFFFFFF, double 0x7FEFFFFFFFFFFFFF, metadata !"round.tonearest", metadata !"fpexcept.strict") #[[ATTR3]] [ "fp.control"(metadata !"rte"), "fp.except"(metadata !"strict") ]
331+
; CHECK-NEXT: [[RESULT:%.*]] = call double @llvm.experimental.constrained.fadd.f64(double 0x7FEFFFFFFFFFFFFF, double 0x7FEFFFFFFFFFFFFF, metadata !"round.tonearest", metadata !"fpexcept.strict") #[[ATTR0]]
332332
; CHECK-NEXT: ret double [[RESULT]]
333333
;
334334
entry:
@@ -492,7 +492,7 @@ entry:
492492
define i1 @cmp_eq_nan_01() #0 {
493493
; CHECK-LABEL: @cmp_eq_nan_01(
494494
; CHECK-NEXT: entry:
495-
; CHECK-NEXT: [[RESULT:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f64(double 0x7FF4000000000000, double 1.000000e+00, metadata !"oeq", metadata !"fpexcept.strict") #[[ATTR3]] [ "fp.except"(metadata !"strict") ]
495+
; CHECK-NEXT: [[RESULT:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f64(double 0x7FF4000000000000, double 1.000000e+00, metadata !"oeq", metadata !"fpexcept.strict") #[[ATTR0]]
496496
; CHECK-NEXT: ret i1 [[RESULT]]
497497
;
498498
entry:
@@ -503,7 +503,7 @@ entry:
503503
define i1 @cmp_eq_nan_02() #0 {
504504
; CHECK-LABEL: @cmp_eq_nan_02(
505505
; CHECK-NEXT: entry:
506-
; CHECK-NEXT: [[RESULT:%.*]] = call i1 @llvm.experimental.constrained.fcmps.f64(double 0x7FF4000000000000, double 1.000000e+00, metadata !"oeq", metadata !"fpexcept.strict") #[[ATTR3]] [ "fp.except"(metadata !"strict") ]
506+
; CHECK-NEXT: [[RESULT:%.*]] = call i1 @llvm.experimental.constrained.fcmps.f64(double 0x7FF4000000000000, double 1.000000e+00, metadata !"oeq", metadata !"fpexcept.strict") #[[ATTR0]]
507507
; CHECK-NEXT: ret i1 [[RESULT]]
508508
;
509509
entry:
@@ -515,7 +515,7 @@ entry:
515515
define i1 @cmp_eq_nan_03() #0 {
516516
; CHECK-LABEL: @cmp_eq_nan_03(
517517
; CHECK-NEXT: entry:
518-
; CHECK-NEXT: [[RESULT:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f64(double 0x7FF8000000000000, double 1.000000e+00, metadata !"oeq", metadata !"fpexcept.strict") #[[ATTR3]] [ "fp.except"(metadata !"strict") ]
518+
; CHECK-NEXT: [[RESULT:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f64(double 0x7FF8000000000000, double 1.000000e+00, metadata !"oeq", metadata !"fpexcept.strict") #[[ATTR0]]
519519
; CHECK-NEXT: ret i1 false
520520
;
521521
entry:
@@ -526,7 +526,7 @@ entry:
526526
define i1 @cmp_eq_nan_04() #0 {
527527
; CHECK-LABEL: @cmp_eq_nan_04(
528528
; CHECK-NEXT: entry:
529-
; CHECK-NEXT: [[RESULT:%.*]] = call i1 @llvm.experimental.constrained.fcmps.f64(double 0x7FF8000000000000, double 1.000000e+00, metadata !"oeq", metadata !"fpexcept.strict") #[[ATTR3]] [ "fp.except"(metadata !"strict") ]
529+
; CHECK-NEXT: [[RESULT:%.*]] = call i1 @llvm.experimental.constrained.fcmps.f64(double 0x7FF8000000000000, double 1.000000e+00, metadata !"oeq", metadata !"fpexcept.strict") #[[ATTR0]]
530530
; CHECK-NEXT: ret i1 [[RESULT]]
531531
;
532532
entry:

llvm/unittests/IR/IRBuilderTest.cpp

Lines changed: 97 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -402,11 +402,57 @@ TEST_F(IRBuilderTest, ConstrainedFP) {
402402
EXPECT_FALSE(verifyModule(*M));
403403
}
404404

405+
// Check call creation in strictfp function if the builder object does not
406+
// specify default values for rounding and exception behavior.
407+
TEST_F(IRBuilderTest, StrictFPCallDefault) {
408+
F->addFnAttr(Attribute::StrictFP);
409+
410+
IRBuilder<> Builder(BB);
411+
Builder.setIsFPConstrained(true);
412+
413+
GlobalVariable *GVDouble = new GlobalVariable(
414+
*M, Type::getDoubleTy(Ctx), true, GlobalValue::ExternalLinkage, nullptr);
415+
Value *FnArg = Builder.CreateLoad(GVDouble->getValueType(), GVDouble);
416+
Function *Fn = Intrinsic::getOrInsertDeclaration(M.get(), Intrinsic::trunc,
417+
{Type::getDoubleTy(Ctx)});
418+
419+
// Function call without explicit bundles. By default it has strict exception
420+
// behavior.
421+
CallInst *CI = Builder.CreateCall(Fn, {FnArg});
422+
EXPECT_EQ(Intrinsic::trunc, CI->getIntrinsicID());
423+
EXPECT_FALSE(CI->getOperandBundle(LLVMContext::OB_fp_control).has_value());
424+
EXPECT_TRUE(CI->getOperandBundle(LLVMContext::OB_fp_except).has_value());
425+
std::optional<RoundingMode> RM = CI->getRoundingMode();
426+
EXPECT_FALSE(RM.has_value());
427+
std::optional<fp::ExceptionBehavior> EB = CI->getExceptionBehavior();
428+
EXPECT_TRUE(EB.has_value());
429+
EXPECT_EQ(fp::ebStrict, *EB);
430+
EXPECT_TRUE(CI->getMemoryEffects().doesAccessInaccessibleMem());
431+
432+
// Function call with explicit bundles.
433+
SmallVector<OperandBundleDef, 2> OpBundles;
434+
Builder.createFPExceptionBundle(OpBundles, fp::ebIgnore);
435+
CI = Builder.CreateCall(Fn, {FnArg}, OpBundles);
436+
EXPECT_EQ(Intrinsic::trunc, CI->getIntrinsicID());
437+
EXPECT_FALSE(CI->getOperandBundle(LLVMContext::OB_fp_control).has_value());
438+
EXPECT_TRUE(CI->getOperandBundle(LLVMContext::OB_fp_except).has_value());
439+
RM = CI->getRoundingMode();
440+
EXPECT_FALSE(RM.has_value());
441+
RoundingMode Rounding = CI->getRoundingMode().value_or(RoundingMode::Dynamic);
442+
EXPECT_EQ(RoundingMode::Dynamic, Rounding);
443+
EB = CI->getExceptionBehavior();
444+
EXPECT_TRUE(EB.has_value());
445+
EXPECT_EQ(fp::ebIgnore, *EB);
446+
EXPECT_TRUE(CI->getMemoryEffects().doesAccessInaccessibleMem());
447+
}
448+
449+
// Check call creation in strictfp function if the builder object specifies
450+
// default values for rounding and exception behavior.
405451
TEST_F(IRBuilderTest, StrictFPCall) {
406452
F->addFnAttr(Attribute::StrictFP);
407453

408454
IRBuilder<> Builder(BB);
409-
Builder.setDefaultConstrainedExcept(fp::ebStrict);
455+
Builder.setDefaultConstrainedExcept(fp::ebIgnore);
410456
Builder.setDefaultConstrainedRounding(RoundingMode::TowardZero);
411457
Builder.setIsFPConstrained(true);
412458

@@ -416,28 +462,70 @@ TEST_F(IRBuilderTest, StrictFPCall) {
416462

417463
// Function calls, that may depend on FP options, gets fp bundles in strictfp
418464
// environment.
419-
Function *Fn = Intrinsic::getOrInsertDeclaration(
465+
Function *Fn = Intrinsic::getOrInsertDeclaration(M.get(), Intrinsic::trunc,
466+
{Type::getDoubleTy(Ctx)});
467+
CallInst *CI = Builder.CreateCall(Fn, {FnArg});
468+
EXPECT_EQ(Intrinsic::trunc, CI->getIntrinsicID());
469+
EXPECT_FALSE(CI->getOperandBundle(LLVMContext::OB_fp_control).has_value());
470+
EXPECT_TRUE(CI->getOperandBundle(LLVMContext::OB_fp_except).has_value());
471+
std::optional<RoundingMode> RM = CI->getRoundingMode();
472+
EXPECT_FALSE(RM.has_value());
473+
std::optional<fp::ExceptionBehavior> EB = CI->getExceptionBehavior();
474+
EXPECT_TRUE(EB.has_value());
475+
EXPECT_EQ(fp::ebIgnore, *EB);
476+
EXPECT_TRUE(CI->getMemoryEffects().doesAccessInaccessibleMem());
477+
478+
// Explicit bundle arguments override builder default values.
479+
SmallVector<OperandBundleDef, 2> OpBundles;
480+
Builder.createFPExceptionBundle(OpBundles, fp::ebIgnore);
481+
CI = Builder.CreateCall(Fn, {FnArg}, OpBundles);
482+
EXPECT_EQ(Intrinsic::trunc, CI->getIntrinsicID());
483+
EXPECT_FALSE(CI->getOperandBundle(LLVMContext::OB_fp_control).has_value());
484+
EXPECT_TRUE(CI->getOperandBundle(LLVMContext::OB_fp_except).has_value());
485+
EB = CI->getExceptionBehavior();
486+
EXPECT_TRUE(EB.has_value());
487+
EXPECT_EQ(fp::ebIgnore, *EB);
488+
EXPECT_TRUE(CI->getMemoryEffects().doesAccessInaccessibleMem());
489+
490+
// Legacy constrained intrinsic call.
491+
Fn = Intrinsic::getOrInsertDeclaration(
420492
M.get(), Intrinsic::experimental_constrained_roundeven,
421493
{Type::getDoubleTy(Ctx)});
422494
Value *V = Builder.CreateConstrainedFPCall(Fn, {FnArg});
423495
auto *I = cast<IntrinsicInst>(V);
424496
EXPECT_TRUE(I->getOperandBundle(LLVMContext::OB_fp_except).has_value());
425497
EXPECT_FALSE(I->getOperandBundle(LLVMContext::OB_fp_control).has_value());
426498
EXPECT_EQ(Intrinsic::experimental_constrained_roundeven, I->getIntrinsicID());
427-
EXPECT_EQ(fp::ebStrict, I->getExceptionBehavior());
499+
EXPECT_EQ(fp::ebIgnore, I->getExceptionBehavior());
428500
MemoryEffects ME = I->getMemoryEffects();
429501
EXPECT_TRUE(ME.doesAccessInaccessibleMem());
430502

431503
// Function calls, that do not depend on FP options, does not have
432504
// fp bundles.
433505
Fn = Intrinsic::getOrInsertDeclaration(M.get(), Intrinsic::fabs,
434506
{Type::getDoubleTy(Ctx)});
435-
V = Builder.CreateCall(Fn, {FnArg});
436-
I = cast<IntrinsicInst>(V);
437-
EXPECT_FALSE(I->getOperandBundle(LLVMContext::OB_fp_except).has_value());
438-
EXPECT_FALSE(I->getOperandBundle(LLVMContext::OB_fp_control).has_value());
439-
ME = I->getMemoryEffects();
440-
EXPECT_FALSE(ME.doesAccessInaccessibleMem());
507+
CI = Builder.CreateCall(Fn, {FnArg});
508+
EXPECT_FALSE(CI->getOperandBundle(LLVMContext::OB_fp_except).has_value());
509+
EXPECT_FALSE(CI->getOperandBundle(LLVMContext::OB_fp_control).has_value());
510+
EXPECT_FALSE(CI->getMemoryEffects().doesAccessInaccessibleMem());
511+
}
512+
513+
TEST_F(IRBuilderTest, FPMemoryEffects) {
514+
IRBuilder<> Builder(BB);
515+
GlobalVariable *GVDouble = new GlobalVariable(
516+
*M, Type::getDoubleTy(Ctx), true, GlobalValue::ExternalLinkage, nullptr);
517+
Value *FnArg = Builder.CreateLoad(GVDouble->getValueType(), GVDouble);
518+
Function *Fn = Intrinsic::getOrInsertDeclaration(M.get(), Intrinsic::trunc,
519+
{Type::getDoubleTy(Ctx)});
520+
521+
CallInst *CI = Builder.CreateCall(Fn, {FnArg});
522+
EXPECT_EQ(Intrinsic::trunc, CI->getIntrinsicID());
523+
EXPECT_FALSE(CI->getOperandBundle(LLVMContext::OB_fp_control).has_value());
524+
EXPECT_FALSE(CI->getOperandBundle(LLVMContext::OB_fp_except).has_value());
525+
EXPECT_TRUE(CI->getMemoryEffects().doesNotAccessMemory());
526+
527+
F->addFnAttr(Attribute::StrictFP);
528+
EXPECT_TRUE(CI->getMemoryEffects().doesAccessInaccessibleMem());
441529
}
442530

443531
TEST_F(IRBuilderTest, ConstrainedFPIntrinsics) {

0 commit comments

Comments
 (0)